0
936views
Write a program to generate following patterns

enter image description here

Subject : Structured Programming Approach

Title : Control Structures

Difficulty : Medium

1 Answer
0
4views

Program a):

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

int main() {
    int i,j;
    int n;
    clrscr();
    printf("\n\n\t Please enter total rows");
    scanf("%d", &n);

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

    getch();
    return 0;
}

Program b):

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

int main() {
    int i,j;
    int n;
    int k;
    clrscr();
    printf("\n\n\t Please enter total rows");
    scanf("%d", &n);

    printf("\n\n");
    printf("  1"); printf("\n\n");
    printf("  2  3");
    k = 3;

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

    getch();
    return 0;
}
Please log in to add an answer.