WAP to create the multiplication table for size 2 to 10. The size is input by the user.
#include <iostream>
using namespace std;
int main()
{
int a;
cout << "Enter a number for to view its table: ";
cin >> a;
for (int i = 1; i <= 10; ++i) {
cout << a << " * " << i << " = " << a * i << endl;
}
return 0;
}
Or
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
int col;
cout<<"Enter the number:";
cin>>col;
for(int i=2;i<=col;i++){
cout<<setw(6)<<i;
}
cout<<endl;
for(int i=1;i<col;i++){
cout<<setw(6)<<"_______";
}
cout<<endl;
for(int i=1;i<=10;i++){
for(int j=2;j<=col;j++){
cout<<setw(6)<<i*j;
}
cout<<endl;
}
return 0;
}
0 Comments
Post a Comment