[2] Write a program that displays n depth * pyramid. The value of “n” will be input from the user of your program.(n>0)
For example,if n is 4, the program displays
*
* * *
* * * * *
* * * * * * *
1
Expert's answer
2014-10-22T13:27:24-0400
#include <stdlib.h> #include <iostream> #include <stdio.h> #include <cstdlib> using namespace std; int main() { int n; int x = 1; cout<<"Enter the n : "; cin>>n; system("cls"); for (int i = 1; i <= n; i++) { for (int k = 1; k <= (n-i); k++) cout << " "; for (int j = 1; j <= x; j++) cout<<"*"; cout<<endl; x+=2; } system("pause"); return 0; }
Comments
Leave a comment