Q. Write a C program to print the following number triangle or pyramid design as:
1
121
12321
1234321
Ans.
/*c program for number triangle design*/
#include<stdio.h>
int main()
{
int num,r,c,z;
printf("Enter any number : ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(c=1; c<=r; c++)
printf("%d",c);
for(z=r-1; z>=1; z--)
printf("%d",z);
printf("\n");
}
getch();
return 0;
}
The output of above program would be:
Learners also read:
1. Character Triangle pattern as:
A
ABA
ABCBA
ABCDCBA
ABCBA
ABA
A
1
121
12321
1234321
Ans.
/*c program for number triangle design*/
#include<stdio.h>
int main()
{
int num,r,c,z;
printf("Enter any number : ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(c=1; c<=r; c++)
printf("%d",c);
for(z=r-1; z>=1; z--)
printf("%d",z);
printf("\n");
}
getch();
return 0;
}
The output of above program would be:
Figure : Screen shot for Number Triangle C program |
Learners also read:
1. Character Triangle pattern as:
A
ABA
ABCBA
ABCDCBA
ABCBA
ABA
A
Comments
Post a Comment