Wednesday, 25 May 2016

Write a program that uses nested loops to display the following lines.
 
                             1        2        4        6
                             2        2        4        6
                             3        2        4        6
                             4        2        4        6

Solution:

             #include<iostream.h>
             #include<conio.h>
             void main()
             {
                  clrscr();
                  for(int i = 1; i <= 4; i++)
                  {
                       cout<<i;
                       for(int j =2; j <= 6; j+= 2)
                             cout<<" "<<j;
                      cout<<endl;
                }
              getch();
            }

No comments:

Post a Comment