Assignment - Pyramid Pattern of Asterisks
----------QUESTION_DESCRIPTION_START----------
You are given an integer `n`. Your task is to print a pyramid pattern of asterisks (`*`) with `n` row
In this pyramid pattern, the first row contains 1 asterisk, the second row contains 3 asterisks, the
third row contains 5 asterisks, and so on. Each row should be centered by placing the appropriate
number of leading spaces before the asterisks so that the pyramid is symmetric.
Example 1:
Input:
3
Output:
*
***
*****
Example 2:
Input:
5
Output:
*
***
*****
*******
*********
Your Task:
- Complete the function printPyramid that takes an integer n as input and prints the pyramid pattern
of height n using asterisks.
- Function Signature:
void printPyramid(int n) (C++)
def print_pyramid(self, n) (Python)
public static void printPyramid(int n) (Java)
Constraints:
- 1 <= n <= 100
Input Format:
- A single integer n on the first line, representing the number of rows of the pyramid.
Output Format:
- The pyramid pattern of asterisks with n rows.
----------QUESTION_DESCRIPTION_END----------
----------SHORT_TEXT_START----------
Pyramid Pattern of Asterisks
----------SHORT_TEXT_END----------
----------QUESTION_LEVEL_START----------
EASY
----------QUESTION_LEVEL_END----------
----------CODE_CONTENT_CPP_START----------
#include <bits/stdc++.h>
using namespace std;
class solution {
public:
void printPyramid(int n) {
// Write your code here...
}
};
----------CODE_CONTENT_CPP_END----------
----------CODE_CONTENT_PYTHON_START----------
class solution:
def print_pyramid(self, n):
# Write your code here...
pass
----------CODE_CONTENT_PYTHON_END----------
----------CODE_CONTENT_JAVA_START----------
import [Link].*;
public class Solution {
public static void printPyramid(int n) {
// Write your code here...
}
}
----------CODE_CONTENT_JAVA_END----------