Saturday, December 5, 2015

Pyramid Program in C - Type #1


Program #5

Description:
Pyramid Type #1

#include "stdio.h"
#include "conio.h"


int main() {
 int i,j,k,n;

 /* clear the screen */
 clrscr();

 printf(" Enter a number to make Type #1 Pramid:\n ");
 scanf("%d", &n);

 /* Validate input */
 if (n < 2 || n > 10){
   return 0;
 }

 /* Make some space between input and Pramid */
 printf("\n\n");

 for (i=1; i<=n; i++) {
   /* move cursor to center to make pramid view */
   for (k=1; k<=(n-i); k++) printf(" ");

   for (j=1; j<=i; j++){
     printf("%d ", i);
   }

   /* Move to next line */
   printf("\n");
 }

 /* Wait after print Pramid */
 getch();
 return 1;
}



No comments:

Post a Comment

Popular Posts