Given an integer n. Print a pyramid made up of symbol '*' of height n.
Example:
Input: n = 3
Output:
* *** *****
Approach:
C++
#include <bits/stdc++.h>using namespace std;int main(){int n = 3;for (int i = 1; i <= n; i++){for (int j = 1; j <= n - i; j++)cout << " ";for (int k = 0; k < 2 * i - 1; k++)cout << "*";cout << "\n";}cout << "\n";return 0;}
No comments:
Post a Comment