Answer to Question #284722 in C++ for papi

Question #284722

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


1
Expert's answer
2022-01-13T07:47:46-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;

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