Programming for Problem Solving (3110003)

BE | Semester-1   Winter-2019 | 07-01-2020

Q2) (c)

Construct ‘C’ program to print the following pattern using loop statement.
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

Program
#include <stdio.h>
void main() {
    int n,i,j;
    printf("Enter n: ");
    scanf("%d",&n);
    for(i=1;i<=n;i++) {
        for(j=1;j<=i;j++) {
            printf("%2d",i);
        }
        printf("\n");
    }
}

OUTPUT:
Enter n: 5
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5