Hi, i'm kinda new to programming. So i got stuck trying to figure out how to program this :
To prompt user to enter an integer and then display the corresponding multiplication table for eg.
Enter an integer : 2
2 X 1 = 2
2 X 2 = 4
2 X 3 = 6
.
.
.
2 X 10 = 20
So i need someone to explain how to do it using while loop and / or for loop.
Thanx.
2 Replies - 21233 Views - Last Post: 18 May 2008 - 06:00 AM
Replies To: To Program a multiplication table using while loop
#2
Re: To Program a multiplication table using while loop
Posted 18 May 2008 - 04:59 AM
Here is how to do it with a while loop; Doing it with a for loop would be very similar.
#include <iostream>
using namespace std;
int main(){
int counter = 1; //initialise a counter that will start at 1
int input;
//input
cout << "Enter an integer: ";
cin >> input;
cout << endl;
//do this while your counter is less than 13 (stops at 12)
while (counter < 13){
//display input, a string "x" , your counter, then multiply the two and display the answer.
cout << input << "x" << counter << "= " << input*counter << endl;
//increment your counter, same as (counter = counter + 1)
counter ++;
}
system("pause");
return 0;
}
#3
Re: To Program a multiplication table using while loop
Posted 18 May 2008 - 06:00 AM
you could use a for loop alternatively...
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|