Thursday 26 January 2012

Write a C program to construct a pyramid of numbers.

1
2 3
4 5 6
7 8 9 10
11 12 13 14 15



#include<stdio.h>
#include<conio.h>
void main( )
{
    int r, c, num=1 ,len;
    clrscr( );
    printf("Enter the required no. of rows:");
    scanf("%d", &len);
    for( r=1; r<=len; r++ )
    {
        printf("\n");
        for(c=1 ; c<=r; c++)
        {
            printf("%2d ", num);
            num++;
        }
    }
    getch( );
}

No comments:

Post a Comment