Program to print the following pyramid of characters in C

C program to print the following character pyramid:

A
BA
ABA
BABA
ABABA


Solution:


/*c program for character pyramid*/
#include<stdio.h>
int main()
{
int num,r,c;
char ch='A',st='B';
printf("Enter number of rows: ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(c=r; c>=1; c--)
{
if(c%2==0)
printf("%c", st);
else
printf("%c", ch);
}
printf("\n");
}
return 0;
}


Output:
birwa.org


Post a Comment