Friday, 6 January 2017

Assume that you want to generate a table of multiples of any given number. Write a pro- gram that allows the user to enter the number and then generates the table, formatting it into 10 columns and 20 lines. Interaction with the program should look like this (only the first three lines are shown): Enter a number: 7 7 14 21 28 35 42 49 56 63 70 77 84 91 98 105 112 119 126 133 140 147 154 161 168 175 182 189 196 203 210

Leave a Comment
Object-Oriented Programming in C++ Fourth Edition By Robert Lafore Chapter-3 C++ Loops and Decisions  -- Questions+Exercises

Question:

Assume that you want to generate a table of multiples of any given number. Write a pro- gram that allows the user to enter the number and then generates the table, formatting it into 10 columns and 20 lines. Interaction with the program should look like this (only the first three lines are shown):

Enter a number: 7
7   14   21   28   35   42   49   56   63   70
77   84   91   98  105  112  119  126  133  140
147  154  161  168  175  182  189  196  203  210

Explanation:
Below mention code is compiled in Visual Studio 2015 and Code Blocks 13.12,output snap is attached.. If any problem you feel and you want some explanation feel free to contact us.

Code:

/**************************************************|
/*************C++ Programs And Projects************|
***************************************************/
#include <iostream>
#include <iomanip>                     //for setw()
using namespace std;
int main()
{
       unsigned long n;                    //number
       cout << "\nEnter a number : ";
       cin >> n;                           //get number
       for (int j = 1; j <= 200; j++)           //loop from 1 to 200
       {
              cout << setw(5) << j*n << "  "//print multiple of n
              if (j % 10 == 0)                  //every 10 numbers,
                     cout << endl;                 //start new line
       }
       return 0;

 }

Output:
Assume that you want to generate a table of multiples of any given number. Write a pro- gram that allows the user to enter the number and then generates the table, formatting it into 10 columns and 20 lines. Interaction with the program should look like this (only the first three lines are shown):  Enter a number: 7 7   14   21   28   35   42   49   56   63   70 77   84   91   98  105  112  119  126  133  140 147  154  161  168  175  182  189  196  203  210



Related Articles:



If You Enjoyed This, Take 5 Seconds To Share It

0 Questions: