In: Computer Science
- Write a function with a parameter called A (which is between 1 and 10) and prints the multiplication table for 1 to A. • Note: Do not need to draw the horizontal and vertical lines. • Example for A = 10.
#include <iostream>
using namespace std;
/*
Uncomment the code if you want the output in this
format
X 1 2 3 4
1 1 2 3 4
2 2 4 6 8
3 3 6 9 12
4 4 8 12 16
Else if you want the outout in this format
1 2 3 4
2 4 6 8
3 6 9 12
4 8 12 16
Both these examples are for n = 4
*/
void multiplicationTable(int a) {
//cout<<"X ";
// for(int i=1;i<=a;i++) {
// cout<<i<<" ";
// }
//cout<<endl;
for (int i=1;i<=a;i++) {
//cout<<i<<" ";
for(int j=1;j<=a;j++) {
cout<<j*i<<" ";
}
cout<<endl;
}
}
int main() {
int a;
cin>>a;
multiplicationTable(a);
}