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;
}
Related Programs:
Q. Write a C program to print the for following number triangle:
123456654321
1234554321
12344321
123321
1221
11
You Might Also Like:
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;
}
/***********************************************************
The output of above program would be:
************************************************************/
Figure: 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
You Might Also Like:
Sir Please provide me c code for this pattern.
ReplyDeleteA B C D E D C B A
A B C D C B A
A B C B A
A B A
A
@pradeep Tiwari
DeleteYour required character pattern C program source code :
http://cprogrammingcodes.blogspot.com/2015/09/character-pattern-program-in-c.html
int printPyramid(char initCh, char finCh)
ReplyDelete{
//checking whether the given combination is right or wrong
if(!((finCh >= initCh)&
(((initCh >=65)&(finCh<=90))|((initCh >=97)&(finCh<=122)))))
{
printf("Please insert the correct combination.");
return 0;
}
// Take register storage class so that the processing become fast as register variables operate fastest
// as coapared to other storage class variables.
register int m = initCh;
register int lastInd = ((finCh - initCh)+1)<<1; //left shift (equivalent to multiplication by 2),but more faster than the multiplication.
int heightOfPyramid = lastInd;
/* Count down from N to 0 is always faster then counting from 0 to N.
* Reason as following -
* Count down from N to 0 -> Load iteration i, compare and jump if it is less then or equal to zero (less instraction at H/W level)
* Count down from 0 to N -> Load i , load N, sub i and N compare and jump if it is less then or equal to zero (more instraction at H/W level)
*/
for(lastInd; lastInd>0; lastInd--) // loop over the heigh of the pyramid
{
if((lastInd%2)== 0) // print the even string like abccba
{
for(m = initCh; m<=finCh; m++) //print in increasing order like abc
printf("%c", m);
for(--m; m>=initCh; m--) //print in decreasing order like cba
printf("%c",m);
printf("\n");
}
else // print the odd string like abcba
{
for(m = initCh; m=initCh; --m) //print in decreasing order like cba
printf("%c",m);
printf("\n");
finCh--;
}
}
return heightOfPyramid;
}
Input an alphabet from the user and display pattern as follows.
ReplyDeleteIf user press 'G' , output should be as:
A B C D E F G F E D C B A
A B C D E F F E D C B A
A B C D E E D C B A
A B C D D C B A
A B C C B A
A B B A
A A
#Shruti Suryawanshi
DeleteYour required character pattern as above pattern C program source code at:
http://cprogrammingcodes.blogspot.com/2015/09/character-pattern-program-in-c.html
STRING IS INDIA
ReplyDeleteOUTPUT SHOULD BE:
1.)
I
.N
..D
...I
....A
2.)
A
II
DDD
NNNN
IIIII
ABCDEF
ReplyDeleteBCDEF
CDEF
DEF
EF
F
help for this output guys..c program
Whats the pattern for
ReplyDeleteINDIAIDNI
INDI IDNI
IND DNI
IN NI
I I