program to print the pyramid of numbers.

program to print the pyramid of numbers as follows :


     1
    123
   12345
  1234567
 123456789





void prntsp(int n)
{
int i;
for(i = 0; i<=n; i++)
printf(" "); // printing n spaces
}

void pyraprint()
{
int i, j, sp = 4;
for(i = 1; i<= 5; i++)
{
prntsp(sp);
for(j = 1; j<= 2*i-1; j++)
{
printf("%d",j);
}
prntsp(sp);
sp--;
printf("\n");
}
}

int main()
{
pyraprint();
return 0;
}


No comments:

Post a Comment