Welcome to my blog this is test

28 June 2012

write a C program to print Floyd’s triangle


//Code:
#include
#include
 void main()
  {
   int i,j,n,sum=0,k;
   clrscr();
   printf("\n Enter the no. of row : ");
    scanf("%d",&n);
     for(i=1;i<=n;i++)
       {
          for(j=n-i;j>0;j--)
             printf(" ");
            for(k=1;k<=i;k++)
              {
               sum=sum+1;
               printf("%2d",sum);
              }
             printf("\n");
       }
    getch();
  }

/*Output:
Enter the no. of row : 6
                    1
                  2   3
               4   5   6
             7   8   9  10
          11 12 13 14 15
         16  17 18 19 20 21

No comments:

Post a Comment