Rabu, 09 Desember 2015

Making Pyramid with C/C++

#include<stdio.h>
#include<conio.h>

void main()
{
int i = 0, j , n ;
clrscr();
printf("How many rows in pyramid:");
scanf("%d",&n);

while(i<n)
{
j=0;
while(j<=i)
{
gotoxy(30+j,10+i);
printf("%d",j);
j++;
}
j=0;
while(j<=i)
{
gotoxy(30-j,10+i);
printf("%d",j);
j++;
}
i++;
printf("\n");
}

getch();
}

Remarks
For making two sides pyramid we have used two while loops and another while loop for controlling rows. Here gotoxy () function takes the curser to the specified location.

Tidak ada komentar:

Posting Komentar