Showing posts with label 1 23 456 78910 triangle. Show all posts
Showing posts with label 1 23 456 78910 triangle. Show all posts

9.24.2011

Floyd's triangle

Q. Write a C program to floyd algorithm number triangle in C as:

  1
  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;
}

/*************************************************************
The output of above program would be:
**************************************************************/

Output of Floyd algorithm number triangle C program
Figure: Screen shot for Floyd algorithm number triangle C program

You might also like to read:


      A
      B C
      D  E  F
      G  H  I J


      9
      8  7
      6  5  4
      3  2  1  0 
         

     1
     2  3
     4  5  6
     7  8  9  10
     4  5  6
     2  3
     1