4.01.2013

Rectangular Star Pyramid

Q. write a c program to print the following star rectangle design:

********
*      *
*      *
********


Ans.

/*c program for star rectangle design*/
#include<stdio.h>
int main()
{
 int cols,rows,r,c,sp;
 printf("Enter no. of columns: ");
 scanf("%d", &cols);
 printf("Enter no. of rows: ");
 scanf("%d", &rows);
 for(r=1; r<=cols; r++)
    printf("*");
 printf("\n");
 for(c=1; c<=rows-2; c++)
 {
    printf("*");
    for(sp=1; sp<=cols-2; sp++)
       printf(" ");
    printf("*\n");
 }
 for(r=1; r<=cols; r++)
    printf("*");
 getch();
 return 0;
}

The output of above program would be:

Output of Rectangle Star Pyramid C program
Figure: Screen shot of Rectangle Star pyramid C program

3 comments:

  1. plz upload M pattern in c.

    ReplyDelete
    Replies
    1. @Amit Gupta,

      The M design pattern program in C source code is:

      http://cprogrammingcodes.blogspot.com/2014/09/how-to-print-m-shape-pyramid-in-c.html

      Delete