Wednesday, 25 May 2016

Write a program that uses nested for loops to display the multiplication table shown below.

                                 1          2          3          4          5
                                 2          4          6          8         10
                                 3          6          9         12        15
                                 4          8         12        16        20
                                 5         10        15        20        25

Solution:

                     #include<iostream.h>
                     #include<conio.h>
                     void main()
                     {
                             int m, n;
                             clrscr();
                             m = 1;
                             while(m <=5)
                             {
                                n = 1;
                               while(n <= 5)
                               {
                                  cout<<"\t"<<m*n;
                                  n++
                               }
                                cout<<"\n";
                                m++;
                        }
                        getch();
                    }

No comments:

Post a Comment