# To Program a multiplication table using while loop

Page 1 of 1

## 2 Replies - 64709 Views - Last Post: 18 May 2008 - 06:00 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=52405&amp;s=24d0c27f29340da0e11dcfe89218814b&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 hottemp

Reputation: 0
• Posts: 2
• Joined: 18-May 08

# To Program a multiplication table using while loop

Posted 18 May 2008 - 04:28 AM

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.

Is This A Good Question/Topic? 0

## Replies To: To Program a multiplication table using while loop

### #2 Wr4i7h

Reputation: 0
• Posts: 14
• Joined: 16-May 08

## 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 ajaymatrix

• D.I.C Regular

Reputation: 1
• Posts: 410
• Joined: 15-May 07

## Re: To Program a multiplication table using while loop

Posted 18 May 2008 - 06:00 AM

you could use a for loop alternatively...