Computer Science, asked by banerjeesubhojit92, 2 months ago

b. Print the following pattern
1
12
123
1234
1 2 3 4 5​

Answers

Answered by anindyaadhikari13
2

Answer:

This is the required program for the question.

1. In Java.

public class Java {

public static void main(String[] args) {

int i, j;

for(i=1;i<=5;i++) {

for(j=1;j<=i;j++)

System.out.print(j+" ");

System.out.println();

}

}

}

2. In Python.

for i in range(1,6):

for j in range(1,i+1):

print(j,end=" ")

print()

3. In C.

#include <stdio.h>

void main() {

int i, j;

for(i=1;i<=5;i++) {

for(j=1;j<=i;j++)

printf("%d ", j);

printf("\n");

}

}

4. In C++

#include <iostream>

using namespace std;

int main() {

int i,j;

for(i=1;i<=5;i++) {

for(j=1;j<=i;j++)

cout << j << " ";

cout << endl;

}

return 0;

}

See the attachment for output ☑.

Attachments:
Similar questions