C Programming

C Programming


Equal Character Triangle

Posted: 06 Feb 2014 09:39 AM PST

Q. Write a C program to print the following equal character triangle pattern as:

A
BAB
CBABC
DCBABCD
EDCBABCDE

Ans.

/*c program for Equal Character Triangle pattern*/
#include<stdio.h>
int main()
{
 char ch,r,c;
 printf("Enter Any Character : ");
 scanf("%c", &ch);
 if(ch>='a' && ch<='z')
    ch=ch-32;
 for(r='A'; r<=ch; r++)
 {
   for(c=r; c>='A'; c--)
      printf("%c",c);
   for(c='B'; c<=r; c++)
      printf("%c",c);
   printf("\n");
 }
 getch();
 return 0;
}

/*********************************************
The output of above program would be:
********************************************/

Output of equal character triangle C program
Figure: Screen shot for equal character triangle C program


Related Program:

Equal Number Triangle C program:

1
212
32123
4321234
543212345

Equal Number Triangle

Posted: 06 Feb 2014 09:42 AM PST

Q. Write a C program to print the following equal number triangle pattern as:

1
212
32123
4321234
543212345

Ans.

/*c program for equal number triangle pattern*/
#include<stdio.h>
int main()
{
 int num,r,c;
 printf("Enter Any Number : ");
 scanf("%d", &num);
 for(r=1; r<=num; r++)
 {
   for(c=r; c>=1; c--)
      printf("%d",c);
   for(c=2; c<=r; c++)
      printf("%d",c);
   printf("\n");
 }
 getch();
 return 0;
}

/**********************************************************
The output of above program would be:
***********************************************************/


Output of equal number triangle pattern C program
Figure: Screen shot for equal number triangle C program

Related Programs:

Equal Character Triangle as:

A
BAB
CBABC
DCBABCD


Post a Comment