Q. Write a C program to print the following nested number-character pyramid/pattern as:
A
1
BB
22
CCC
333
Ans.
/*c program for nested number character pyramid*/
#include<stdio.h>
int main()
{
int num,r,c,z,n=1;
char ch='A';
printf("Enter Maximum number : ");
scanf("%d", &num);
for(r=1; r<=num; r++,ch++,n++)
{
for(c=1; c<=2; c++)
{
if(c%2==0)
{
for(z=1; z<=r; z++)
printf("%d",n);
}
else
{
for(z=1; z<=r; z++)
printf("%c",ch);
}
printf("\n");
}
}
getch();
return 0;
}
Related programs:
1. Nested same Symbol Pyramid as:
#
#
##
##
###
###
2. Nested Differ Symbol Pyramid as:
@
#
@@
##
@@@
###
3. Nested Equal same-equal Pyramid as:
@
@
##
##
@@@
@@@
4. Nested Equal Number Pyramid as:
1
1
22
22
333
333
5. Nested Differ Character Pyramid as:
A
A
BB
BB
CCC
CCC
A
1
BB
22
CCC
333
Ans.
/*c program for nested number character pyramid*/
#include<stdio.h>
int main()
{
int num,r,c,z,n=1;
char ch='A';
printf("Enter Maximum number : ");
scanf("%d", &num);
for(r=1; r<=num; r++,ch++,n++)
{
for(c=1; c<=2; c++)
{
if(c%2==0)
{
for(z=1; z<=r; z++)
printf("%d",n);
}
else
{
for(z=1; z<=r; z++)
printf("%c",ch);
}
printf("\n");
}
}
getch();
return 0;
}
/**************************************************************
The output of above program would be:
**************************************************************/
Figure: Screen shot for Nested Number Character Pyramid C program |
Related programs:
1. Nested same Symbol Pyramid as:
#
#
##
##
###
###
2. Nested Differ Symbol Pyramid as:
@
#
@@
##
@@@
###
3. Nested Equal same-equal Pyramid as:
@
@
##
##
@@@
@@@
4. Nested Equal Number Pyramid as:
1
1
22
22
333
333
5. Nested Differ Character Pyramid as:
A
A
BB
BB
CCC
CCC
No comments:
Post a Comment