I'm beginning to learn C++, and I need to write a program that prints n rows of digits. The nth row needs to read 1234...n. Also, if a row has more than 10 digits, the digit after 9 should start from 0. For example:
#include <iostream>
usingnamespace std;
int main()
{
double length;
double row;
double col;
cout << "Enter the number of rows (integer): ";
cin >> length;
for (row = 1; row <= length; row++)
{
for (col = 1; col <= row; col++)
{
cout << col << endl;
}
cout << " " << endl;
}
return (0);
}
My code outputs:
1
1
2
1
2
3
1
2
3
4
1
2
3
4
5
(ect...)
For numbers greater than 10, I need to use x%10 to compute x mod 10.
I'm not sure how to get the output horizontal rather than vertical. I also don't have a great grasp of loops within loops, which probably contributes to my problem. Can anyone help me out? Thanks