My assignment is to write a program that outputs the following columns of numbers using mathematical operators and the loop index.
This is what I want the program to output:
1 10 0 1 1 0
2 20 1 4 2 0
3 30 2 9 3 0
4 40 3 16 4 0
5 50 4 25 0 1
6 60 5 36 1 1
7 70 6 49 2 1
8 80 7 64 3 1
9 90 8 81 4 1
10 100 9 100 0 2
*I couldn't get the top row aligned right. The top row SHOULD be moved over to the right to line up with the columns.
I've got the correct output for columns 1, 2, 3, and 4 but I'm not sure how to get the correct output for columns 5 and 6.
Here is my code:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int a;
int b;
int c;
int d;
int e;
for(int i = 1; i <11; i++)
{
a = i*10;
b = i-1;
c = i * i;
//d = Not Sure What to Do Here;
//e = Not Sure What to Do Here;
cout << left << setw (5) << i << left << setw (5) << a << left << setw (5) << b << left << setw (5) << c << left << setw (5) << d << left << setw (5) << e <<"\n";
}
}
If you run the code as-is, you'll get garbage from variables d and e because they haven't been initialized. So my question is what do I need to do to make variables d and e produce the correct numbers?
Thanks,
Nick