Q. Write a C program to print the following number triangle design:
1
232
34543
4567654
Ans.
/*c program for number triangle design*/
#include<stdio.h>
int main()
{
int num,r,c,s,t,q;
printf("Enter any number : ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(c=r, s=r; c>=1; c--,s++)
printf("%d", s);
for(q=r-1,t=s-2; q>=1; q--,t--)
printf("%d", t);
printf("\n");
}
return 0;
}
The output of above program would be:
1
232
34543
4567654
Ans.
/*c program for number triangle design*/
#include<stdio.h>
int main()
{
int num,r,c,s,t,q;
printf("Enter any number : ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(c=r, s=r; c>=1; c--,s++)
printf("%d", s);
for(q=r-1,t=s-2; q>=1; q--,t--)
printf("%d", t);
printf("\n");
}
return 0;
}
The output of above program would be:
Figure: Screen shot for number pyramid C program |
No comments:
Post a Comment