0
526views
Write a program to generate following patterns

enter image description here

Subject : Structured Programming Approach

Title : Control Structures

Difficulty : Medium

1 Answer
0
1views

C code

#include <stdio.h>
int main() {
/*Two variables where i and j represents rows and columns respectively*/
int i , j;
/*To iterate over 5 rows*/
for (i=1 ; i<=5; i++){
/*To iterate over the columns*/
for (j = 1 ; j <= i;j++){
/*We have to print the values same as column no so print j*/
printf("%d ",j);
}
printf("\n");
}
return 0;
}

Python Code

for i in range(6):
    for j in range(1,i+1):
        print(j,end=" ")
    print()
Please log in to add an answer.