Wednesday 1 February 2012

Number triangle equal

Q. write a C following number triangle :
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5


Ans.


/*c program for number structure*/
#include<stdio.h>
#include<conio.h>
int main()
{
  int num,r,c;
  printf("Enter structure number : ");
  scanf("%d", &num);
  for(r=1; r<=num; r++)
  {
     for(c=1; c<=r; c++)
        printf("%d",r);
     printf("\n");
  }
  return 0;
}
Output:-
Enter structure number : 5

1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

No comments:

Post a Comment