+92 332 4229 857 99ProjectIdeas@Gmail.com

Printing different tables in each row (C++)


Printing different tables in each row
printTables() print tables in each row of specified length as given by the user and it take 3 parameters as an input:
startIndex takes the starting table number.
endIndex takes the ending table number.
Length takes the number of entries in each row.

Code

#include "stdafx.h"
#include "iostream"
#include "conio.h"
#include "iomanip"

using namespace std;

void printTables(int startIndex,int endIndex,int length)
{
   for (int i = startIndex; i <= endIndex; i = i + 1)
   {
      int k = 1;
      for (int j = i; k <= length; j = j + i)
      {
       cout<<setw(5)<<j;  
       k = k + 1;
      }
       cout<<endl;
   }
}

int main()
{
       printTables( 5 , 15 , 8 );

       _getche();
       return 0;
}

Output
    5   10   15   20   25   30   35   40
    6   12   18   24   30   36   42   48
    7   14   21   28   35   42   49   56
    8   16   24   32   40   48   56   64
    9   18   27   36   45   54   63   72
   10   20   30   40   50   60   70   80
   11   22   33   44   55   66   77   88
   12   24   36   48   60   72   84   96
   13   26   39   52   65   78   91  104
   14   28   42   56   70   84   98  112
   15   30   45   60   75   90  105  120

0 comments: