Monday, 1 April 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

No comments:

Post a Comment