Thursday, November 26, 2009

Write a C program to print the given alphabet pyramid -2


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

No comments:

Post a Comment