A B C D E F G F E D C B A
A B C D E F E D C B A
A B C D E D C B A
A B C D C B A
A B C B A
A B A
A
#include<stdio.h>
#incldue<conio.h>
int main( )
{
int r,c,askey,sp;
clrscr( );
for( r=7; r>=1; r-- )
{
for(sp=6; sp>=r; sp--)
printf(" "); //2 spaces
askey=65;
for(c=1; c<=r; c++ )
printf("%2c", askey++ );
for(c=r-1; c>=1; c-- )
printf("%2c", --askey);
printf("\n");
}
getch();
return 0;
}
Output:-
A B C D E F G F E D C B A
A B C D E F E D C B A
A B C D E D C B A
A B C D C B A
A B C B A
A B A
A
Thursday, November 26, 2009
Write a C program to print the given alphabet pyramid -2
Subscribe to:
Post Comments (Atom)
please explain me the program
ReplyDeletethis is wrong program i had try taht the output is different
ReplyDeleteThis is 100% Correct program.
ReplyDeleteI have execute this program at my PC...
please explain me the program
ReplyDelete@gaurav
ReplyDeletethanq 4 uploading this prgm......
askey--;
is missing after printf in 3rd forloop
which gives the above output
can you make it in cpp?? please
ReplyDelete#include
Deletemain()
{
int i,r,c,askey,sp;
printf("Enter how many rows : ");
scanf("%d",&r);
for(i=r;i>=1;i--){
for(sp=6;sp>=i;sp--)
printf(" ");
askey=64;
for(c=1;c<=i;c++)
printf("%2c",++askey);
for(c=i-1;c>=1;c--)
printf("%2c",--askey);
printf("\n");
}
}
This is the correct code. In the post the output was coming a bit different . So small change is required. Try my code. in case of any error. reply me.
Nice! You can also try C code champ for several C programs, codes and tutorials. C codechamp contains a great list of C programs and tutorials.
ReplyDeletehttp:\\ccodechamp.com
Sir, i could not understand the 2nd for loop. if we are taking user input in 'r', and if r=8,9,10 then,doesnt that 2nd for loop shows an error in output?
ReplyDeletein the given code u jst need to change askey=65 to askey=64 & askey++ to ++askey
ReplyDelete3rd foor loop is little bit confusing. Code is correct and working.
ReplyDelete