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

Recommended Answers

All 5 Replies

What are 5 and 6 supposed to compute?
5) maybe %5
6) maybe /5

I'm not sure about e , but for d , you will want to use the modulo operator, % .

For e , as I said I'm not sure, but I think it has to do with integer division by 5.

OK, Thanks for the replies guys. @Frogboy77 Column 5 is supposed to compute 1234012340 and column 6 is 0000111112.

I gave you the answer dude.

I gave you the answer dude.

I'm sorry. Wasn't really paying attention. I got the program working though.


Thanks,
Nick

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.