I've been trying to figure this out for a long time. I have to read in a number from the user, NR, and repeat the outer loop NR times, and use the inner loop to display NR consecutive even values starting with 2 x row number.
For example:
Input: 3
Output:
2 4 6
4 6 8
6 8 10
Input: 4
Output:
2 4 6 8
4 6 8 10
6 8 10 12
8 10 12 14
I'm able to print out the numbers in a square format, however I can't print out the correct numbers. Please help.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
usingnamespace std;
int main()
{
int NR, r, c;
cin >> NR;
for(r=1; r <= NR; r++)
{
for(int c=1; c <= NR; c++)
cout << //I'm unsure of what to put here << " ";
cout << endl;
}
cout << endl; return 0; // DO NOT REMOVE, MODIFY or DELETE.
}
int main()
{
int NR, r, c;
cin >> NR;
for(r=1; r <= NR; r++)
{
for(int c=r; c <= NR+r; c++)//if you dont do NR+r it will print only fraction of the numbers
cout << c*2 << " ";
cout << endl;
}
cout << endl; return 0; // DO NOT REMOVE, MODIFY or DELETE. but why???
}
sorry.... just remove the <= and replace it with < and it will work.....
(didn't see that coming :D)
somewhat like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
int main()
{
int NR, r, c;
cin >> NR;
for(r=1; r <= NR; r++)
{
for(int c=r; c < NR+r; c++)//if you dont do NR+r it will print only fraction of the numbers
cout << c*2 << " ";
cout << endl;
}
cout << endl; return 0; // DO NOT REMOVE, MODIFY or DELETE. but why???
}