hi, have this reverse triangle that i cannot completely solve, hope to get some help. here's my code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int x; //declare the variable
int i = 1,j = 1; //declare the variables
cout<< "Enter a positive odd number: "; //ask user to input how many lines
cin>>x;
for (int i=1;i<=x;i++)
{
for(int j=1; j<=i-1;j++)
{
cout<<" ";
}
for (int j=1; j<=(x-(2*i-2));j++)
{
cout<<j%10;
}
cout<<endl;
}
return 0; //exit the program
}
| |
say, i put in 13,this will produce,
1234567890123
12345678901
123456789
1234567
12345
123
1
|
while my teacher demand output like this,
3210987654321
21098765432
109876543
0987654
98765
876
7
|
my demand it has to be positive and odd number, i still have not made that limitation yet, right now I am focusing on trying produce the desire outcome, therefore I only try positive odd number first.
I also do not know how to fix the excessive spacing at the end. if i omit the "cout<<endl;" it will produce everything in one line, however if i put it in the code, the result is just like that.
thanks for the help guys