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:
Related Articles:
0 Questions:
Post a Comment