Q. Write a C program to design the number triangle pyramid as:
1
121
1231
12341
123451
Ans.
/*c program for number triangle design*/
#include<stdio.h>
int main()
{
int num,r,c,z;
printf("Enter No. of rows : ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(c=1; c<=r; c++)
printf("%d",c);
for(z=1; z<r; z++)
{
printf("%d",z);
break;
}
printf("
");
}
getch();
return 0;
}
The output of above program would be:
1
121
1231
12341
123451
Ans.
/*c program for number triangle design*/
#include<stdio.h>
int main()
{
int num,r,c,z;
printf("Enter No. of rows : ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(c=1; c<=r; c++)
printf("%d",c);
for(z=1; z<r; z++)
{
printf("%d",z);
break;
}
printf("
");
}
getch();
return 0;
}
The output of above program would be:
Figure: Screen shot for Number Triangle Design C program |
0 comments:
Post a Comment