Q. Write a C program for following character triangle.
ABCDEFFEDCBA
ABCDEEDCBA
ABCDDCBA
ABCCBA
ABBA
AA
Ans.
/*c program for character triangle pyramid*/
#include<stdio.h>
#include<conio.h>
int main()
{
char ch,r,c,m,p;
printf("Enter any character: ");
scanf("%c", &ch);
if(ch>='a' && ch<='z')
ch = ch-32;
c=ch;
printf("\n");
for(r='A'; r<=ch; r++,c--)
{
for(m='A'; m<=c; m++)
printf("%c",m);
for(p=c; p>='A'; p--)
printf("%c",p);
printf("\n");
}
getch();
return 0;
}
/************Output************/
Related Programs:
Q. Write a C program to print the for following number triangle:
123456654321
1234554321
12344321
123321
1221
11
or
Q. Write a C program for print the following character pyramid.ABCDEFFEDCBA
ABCDEEDCBA
ABCDDCBA
ABCCBA
ABBA
AA
Ans.
/*c program for character triangle pyramid*/
#include<stdio.h>
#include<conio.h>
int main()
{
char ch,r,c,m,p;
printf("Enter any character: ");
scanf("%c", &ch);
if(ch>='a' && ch<='z')
ch = ch-32;
c=ch;
printf("\n");
for(r='A'; r<=ch; r++,c--)
{
for(m='A'; m<=c; m++)
printf("%c",m);
for(p=c; p>='A'; p--)
printf("%c",p);
printf("\n");
}
getch();
return 0;
}
/************Output************/
Screen shot for character pyramid C program |
Related Programs:
Q. Write a C program to print the for following number triangle:
123456654321
1234554321
12344321
123321
1221
11
Comments
Post a Comment