Answer to Question #284721 in C++ for papi

Question #284721

Generate an (n X m) Multiplication table. Use a nested-loop.


Typical output might be:

input value of n = 12

input value of m = 12


1
Expert's answer
2022-01-09T03:08:53-0500
   #include<iostream>
   #include<iomanip>
   using namespace std;
   int main()
   { 
   int i,j;    
   cout<<"     "<<1;//5 space chars

   for(i = 2;i <= 10;++i)
       cout<<"    "<<i;//4 space chars

   cout<<endl;
   cout<<"   ----|";

   for(i = 2;i <= 10;++i)
       cout<<"----|";

   cout<<endl;

   for(i = 1;i <= 10;++i)
   {
       cout<<setw(2)<<i<<"|";

       for(j = 1;j <= 10;++j)
          cout<<setw(4)<<j*i<<"|";

       cout<<endl;
       cout<<" -|----";

       for(j = 2;j <= 9;++j)
          cout<<"|----";

       cout<<"|----|";
       cout<<endl;

   }
   return 0;
   }



 

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog