Q. Print the following Floyd's triangle :
          1
          2 3
          4 5 6
          7 8 9 10
Ans. 
/*c Program of Floyd's triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int r,c,n,x=1;
 printf("Enter No. of rows of Floyd's triangle : ");
 scanf("%d",&n);
 for(r=1; n>=r; r++)
 {
   for(c=1; c<=r; c++,x++)
       printf(" %d",x);
   printf("\n");
 }
getch();
 return 0;getch();
}
      Output of the above program :
Enter No. of rows of Floyd's triangle : 4
1
 2 3
4 5 6
7 8 9 10
 
No comments:
Post a Comment