i want to make a generic code that prints such output, mean user can enter any value +whole.
*
* *
* * *
* * * *
* * * * *
for 5
and
*
* *
* * *
for 3.
here what i make. but it prints just right triangle. Any helps. thanks in advance.
#include <iostream>
using namespace std;
int main()
{
int val;
cout << "Enter the number: ";
cin >> val;
int t = val;
int x = val;
for(int r = 1; r <= val; r++)
{
for(int c = 1; c <=t ; c++)
{
if(c < x)
{
cout << ' ';
}
else
{
cout << "*";
}
}
cout << endl;
x = x-1;
}
return 0;
}
place 'space' after * in cout, it adjust all your sequence. mean cout << "* "; thats it.