11.03.2012

Floyd Triangle

Q. Write a C program to print the following number pyramid or Floyd triangle:

       1
      2 3
     4 5 6
    7 8 9 10

Ans.

/*c program to print the number pyramid*/
#include<stdio.h>
int main()
{
 int num,r,c,sp,i=1;
 printf("Enter any number : ");
 scanf("%d", &num);
 for(r=1; r<=num; r++)
 {
  for(sp=1; sp<=num-r; sp++)
    printf(" ");
  for(c=1; c<=r; c++,i++)
    printf("%d ",i);  
  printf("\n");
 }
 return 0;
}

The output of above program would be:


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

2 comments:

  1. 1
    23
    456
    78910
    456
    23
    1

    To print this Wat should I do help me pls

    ReplyDelete
    Replies
    1. @Praddos Kanna,

      Your required pattern Floyd triangle C program source code at:

      http://cprogrammingcodes.blogspot.com/2016/01/reverse-floyd-triangle-half-floyd.html

      Delete