HI WELCOME TO SIRIS

How To Print M-Shape Pyramid In C

Leave a Comment

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;
}


/**************************************************************
The output of above M Shape pyramid program will be:
**************************************************************/

Output of M-Shape Pyramid In C
Figure: Screenshot for M-Shape Pyramid In C

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.