7.24.2012

Number structure

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


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


Ans.


/*c program for above number triangle codes*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int r,c,sp,num;
 printf("Enter loop repeat number(rows): ");
 scanf("%d", &num);
 for(r=1; r<=num; r++)
 {
  for(sp=1; sp<=num-r; sp++)
     printf("  ");   //it is 2 blank space
  for(c=1; c<=2*r-1; c++)
     printf(" %d",c);
  printf("\n");
 }
 getch();
 return 0;
}


/**************Output**************/


Output of number pyramid C program
Screen shot for number triangle C program

4 comments:

  1. 1
    1 4 9
    1 4 9 16 25
    1 4 9 16 25 36 49
    1 4 9 16 25 36 49 64 81

    please provide a solution

    ReplyDelete
  2. how to print this program?
    1
    2 2
    3 3 3
    4 4 4 4
    5 5 5 5 5
    6 6 6 6 6 6 i need to it

    ReplyDelete
    Replies
    1. @Farzane Fazil,

      Your required above program source code at:

      http://cprogrammingcodes.blogspot.in/2012/02/number-triangle-equal.html

      Delete
  3. 1
    212
    32123
    4321234
    543212345
    how to solve it?

    ReplyDelete