Computer Science, asked by pratishmoses, 9 months ago

Write a program in java which will ask the user to input a choice ch and the height of the triangle h and print either of the following patterns based on the user’s selection. Ch=1 h=4 output : 1 12 123 1234 Ch=2 h=5 output : 12345 1234 123 12 1

Answers

Answered by pranshuagarwal48
0

Answer:

Simple pyramid pattern

// C++ code to demonstrate star pattern

#include <iostream>

using namespace std;

// Function to demonstrate printing pattern

void pypart(int n)

{

// Outer loop to handle number of rows

// n in this case

for (int i = 0; i < n; i++) {

// Inner loop to handle number of columns

// values changing acc. to outer loop

for (int j = 0; j <= i; j++) {

// Printing stars

cout << "* ";

}

// Ending line after each row

cout << endl;

}

}

// Driver Function

int main()

{

int n = 5;

pypart(n);

return 0;

}

Explanation:

PLEASE FOLLOW ME

MARK ME AS BRAINLIST.

Similar questions