Q. Write a C program to floyd algorithm number triangle in C as:
  1
2 3
4 5 6
7 8 9 10
2 3
4 5 6
7 8 9 10
Ans:
/* c program for floyd algorithm number triangle */
#include<stdio.h>
int main()
{
 int r,c,n,x=1;
 printf("Enter No. Of rows : ");
 scanf("%d", &n);
 for(r=1; r<=n; r++)
 {
   for(c=1; c<=r; c++,x++)
       printf(" %d",x);
   printf("\n");
 }
 getch();
 return 0;
}
 
 
No comments:
Post a Comment