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;
}
You might also like to read below programs source code:
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
6. Nested Differ Character Pyramid as:
A
11
BBB
2222
CCCC
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 |
You might also like to read below programs source code:
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
6. Nested Differ Character Pyramid as:
A
11
BBB
2222
CCCC
0 komentar:
Post a Comment