2 Replies - 29399 Views - Last Post: 18 May 2008 - 06:00 AM Rate Topic: -----

#1 hottemp  Icon User is offline

  • New D.I.C Head

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

To Program a multiplication table using while loop

Post icon  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  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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;
}

Was This Post Helpful? 0
  • +
  • -

#3 ajaymatrix  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 1
  • View blog
  • 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...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1