Q. Write a C program to print the following number character pyramid as:
1
21A
321AB
4321ABC
54321ABCD
Ans.
/*c program for number character triangle*/
#include<stdio.h>
int main()
{
int num,r,c,p,z;
printf("Enetr no. of rows : ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(c=r; c>=1; c--)
printf("%d",c);
for(z='A',p=r; p>1; p--,z++)
printf("%c",z);
printf("\n");
}
getch();
return 0;
}
The output of above program would be:
1
21A
321AB
4321ABC
54321ABCD
Ans.
/*c program for number character triangle*/
#include<stdio.h>
int main()
{
int num,r,c,p,z;
printf("Enetr no. of rows : ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(c=r; c>=1; c--)
printf("%d",c);
for(z='A',p=r; p>1; p--,z++)
printf("%c",z);
printf("\n");
}
getch();
return 0;
}
The output of above program would be:
Figure: Screen shot for number character pyramid C program |
Comments
Post a Comment