I need to write a program: write a program to display a hexadecimal multiplication table for the number 1 to 16. The first row and first column numbers should be displayed in decimal, but the contents of the table should be displayed in hexadecimal. The program's out should look like:
Hexadecimal Multiplication Table
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
1 1 2 3 4 5 6 7 8 9 a b c d e f 10
2 2 4 6 8 a c e 10 12 14 16 18 1a 1c 1e 20
3 3 6 9 c f 12 15 18 1b 1e 21 24 27 2a 2d 30
4 4 8 c 10 14 18 1c 20 24 28 2c 30 34 38 3c 40
5 5 a f 14 19 1e 23 28 2d 32 37 3c 41 46 4b 50
6 6 c 12 18 1e 24 2a 30 36 3c 42 48 4e 54 5a 60
7 7 e 15 1c 23 2a 31 38 3f 46 4d 54 5b 62 69 70
8 8 10 18 20 28 30 38 40 48 50 58 60 68 70 78 80
9 9 12 1b 24 2d 36 3f 48 51 5a 63 6c 75 7e 87 90
10 a 14 1e 28 32 3c 46 50 5a 64 6e 78 82 8c 96 a0
11 b 16 21 2c 37 42 4d 58 63 6e 79 84 8f 9a a5 b0
12 c 18 24 30 3c 48 54 60 6c 78 84 90 9c a8 b4 c0
13 d 1a 27 34 41 4e 5b 68 75 82 8f 9c a9 b6 c3 d0
14 e 1c 2a 38 46 54 62 70 7e 8c 9a a8 b6 c4 d2 e0
15 f 1e 2d 3c 4b 5a 69 78 87 96 a5 b4 c3 d2 e1 f0
16 10 20 30 40 50 60 70 80 90 a0 b0 c0 d0 e0 f0 100
Here is what I have so far
1 2 3 4 5 6 7 8 9 10 11
|
cout << "Hexadecimal Multiplication Table:" << endl;
for (int y = 1; y <= 16; ++y)
{
cout << setw(3) <<dec<< y << " ";
for (int x = 1; x <= 16; ++x)
cout << setw(5) <<hex<< x*y;
cout << endl;
}
return 0;
}
|
The output prints correctly, but my headers is not in decimal, but in hex.
How can I set it to dec?