# factorial program using while loop

Page 1 of 1

## 2 Replies - 28771 Views - Last Post: 16 September 2009 - 11:04 PMRate 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=126058&amp;s=f5192ff2435dff38f73ab21d025d0634&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 yuggoth

Reputation: 1
• Posts: 15
• Joined: 15-September 09

# factorial program using while loop

Posted 15 September 2009 - 03:46 PM

```#include <iostream>
using namespace std;
int main ()
{
int factor = 1;
int n;
cout << "enter a number to calculate its factorial value :\n";
cin >> n;

while (n >1) {

factor *= n--;

}
cout << "the answer is  " << factor << endl;

}

```

i dont know what the "*=" symbol means, so i dont know whats goin on with the code.

the program does work, but i want to better understand what each line means

thanks

Is This A Good Question/Topic? 0

## Replies To: factorial program using while loop

• Saucy!

Reputation: 6180
• Posts: 23,882
• Joined: 23-August 08

## Re: factorial program using while loop

Posted 15 September 2009 - 04:17 PM

*= means take the left side of the equation, multiply it by the right side and set the left side to the result. So if factor is 5, and n is 4, after executing factor will be 20 (5 * 4). It's a shorthand way of saying factor = factor * n--;.

### #3 yuggoth

Reputation: 1
• Posts: 15
• Joined: 15-September 09

## Re: factorial program using while loop

Posted 16 September 2009 - 11:04 PM

JackOfAllTrades, on 15 Sep, 2009 - 03:17 PM, said:

*= means take the left side of the equation, multiply it by the right side and set the left side to the result. So if factor is 5, and n is 4, after executing factor will be 20 (5 * 4). It's a shorthand way of saying factor = factor * n--;.

great!!!!!

thanks a lot