Format the multiplication table exercise we did in class to include headers. All numbers and lines should be generated with loops. All columns are 4 characters wide, just like in class. The final output should look like this:
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
cout << " |";
for (int i=1; i<=10; i++) {
cout << setw(4) << i;
}
cout << endl;
cout << "----+";
for (int i=1; i<=10; i++) {
cout << "----";
}
cout << endl;
for (int j=1; j<=10; j++) {
cout << setw(4) << j << "|";
for (int i=1; i<=10; i++) {
cout << setw(4) << i*j;
}
cout << endl;
}
return 0;
}
Comments
Leave a comment