Q. WAP to print M shape pyramid In C language as:
* *
** **
* * *
* *
* *
Ans.
/* how to print m shape pyramid in c*/
#include<stdio.h>
int main()
{
int num=5,r,c;
for(r=1; r<=num; r++)
{
for(c=1; c<=num; c++)
{
if( (c==2 || c==3 || c==4) && (r==1) )
printf(" ");
else if( (c==3) && (r==2) )
printf(" ");
else if( (c==2 || c==4) && (r==3) )
printf(" ");
else if( (c==2 || c==3 || c==4 ) && (r==4 || r==5) )
printf(" ");
else
printf("*");
}
printf("\n");
}
getch();
return 0;
}
You might also like:
* *
** **
* * *
* *
* *
Ans.
/* how to print m shape pyramid in c*/
#include<stdio.h>
int main()
{
int num=5,r,c;
for(r=1; r<=num; r++)
{
for(c=1; c<=num; c++)
{
if( (c==2 || c==3 || c==4) && (r==1) )
printf(" ");
else if( (c==3) && (r==2) )
printf(" ");
else if( (c==2 || c==4) && (r==3) )
printf(" ");
else if( (c==2 || c==3 || c==4 ) && (r==4 || r==5) )
printf(" ");
else
printf("*");
}
printf("\n");
}
getch();
return 0;
}
/**************************************************************
The output of above M Shape pyramid program will be:
**************************************************************/
Figure: Screenshot for M-Shape Pyramid In C |
You might also like:
Write a C program that displays the following lines of characters:
ReplyDeleteA
BC
DEF
GHIJ
KLMNO
please help me out ......................
@ G Prasad,
DeleteYour required Floyd Algorithm Character Pattern in C source code at:
http://cprogrammingcodes.blogspot.com/2015/03/floyd-algorithm-character-pattern-in-c.html
Write a C program that generates an addition table that is formatted as follows:
ReplyDelete+ | 0 1 2 3 4
------------------------
0 | 0 1 2 3 4
1 | 1 2 3 4 5
2 | 2 3 4 5 6
3 | 3 4 5 6 7
4 | 4 5 6 7 8
Suggestion: Do not work on the whole problem at once. First write the loop that will print the column headers. Then write the nested loops that will print the body of the table.
please help me out
1 1
ReplyDelete12 21
123 321
1234 4321
123454321
any give this pyramin ans please..........