print an inverted pyramid by using for loop structure and 'setw' manipulator.
#include <iostream>
#include <iomanip>
using namespace std;
void getPyramid(int number){
int n = 0;
for(int m = 1; m < number; m++)
{
cout << setw(m + 5);
for(int i = n ; i < number - n; i++)
cout << number - i ;
cout << endl;
n++;
}
}
int main()
{
int num;
cout << "Enter a number: ";
cin >> num;
getPyramid(num);
return 0;
}
Comments
Leave a comment