What aC program that generates the following change using fo
Solution
#include<iostream>
using namespace std;
int main()
{
int c, d, sc, space = 0, no, ch;
//Loops till 0 is entered
do
{
cout<<\"\ Enter the size of the matrix: \";
cin>>no;
//Loops entered number + 1 number of rows
for(c = no+1; c >= 0; c--)
{
//Adds space in the left size
for(sc = 1; sc <= space; sc++)
{
cout<<\" \";
}
//Displays * symbol
for(d = 1; d <= c; d++)
{
cout<<\"*\"<<\" \";
}
space = space + 2;
cout<<\"\ \";
}
//Reinitialize space to 0 for next display space
space = 0;
cout<<\"\ Press any key to continue ...... 0 to exit \";
cin>>ch;
//Checks the choice for 0 to exit
if(ch == 0)
break;
}while(1);
}
Output:
Enter the size of the matrix: 8
* * * * * * * * *
* * * * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
Press any key to continue ...... 0 to exit 2
Enter the size of the matrix: 4
* * * * *
* * * *
* * *
* *
*
Press any key to continue ...... 0 to exit 0

