Showing posts with label nested loop. Show all posts
Showing posts with label nested loop. Show all posts

Thursday, March 7, 2013

Write a program in C to print following pattern or triangle

Write a program in C to print following pattern or triangle
*
**
***
****
*****
******
*******

Solution:
/*Write a program in C to print following pattern or triangle*/
#include<stdio.h>
#include<conio.h>
main()
{
int n;
clrscr();
printf("Enter number of Rows\t");
scanf("%d",&n);
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
printf("*");}
printf("\n");}
getch();
}

Output: Enter number of Rows      7
*
**
***
****
*****
******
*******
                                                               For Download Click below

Saturday, March 2, 2013

Write a program in C to print following pattern or opposite pyramid or opposite trinagle.

Write a program in C to print following pattern or opposite pyramid or opposite trinagle.
###########
 #########
   #######
    #####
     ###
      #

#include<stdio.h>
#include<conio.h>
main()
{
int n;
clrscr();
printf("Enter the number of rows you want to print\t);
scanf("%d",&n);
for(int r=n;r>=1;r--){
for(int s=1;s<=n-r;s++){
printf(" ");
}
for(int p=1-r;p<r;p++){
printf("#"); \*put anythinh from sajjadsaeed*/
}
printf("\n");
}
getch();
}
                                                             For Download Click below