program for finding factorial of a number using *operator overloading

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2004
Posts: 1
Reputation: suma2411 is an unknown quantity at this point 
Solved Threads: 0
suma2411 suma2411 is offline Offline
Newbie Poster

program for finding factorial of a number using *operator overloading

 
0
  #1
Nov 15th, 2004

can you please help me in writing a program(c++) for finding factorial of a number using * operator overloading?
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: program for finding factorial of a number using *operator overloading

 
0
  #2
Nov 15th, 2004
You know what a factorial is I hope?
Then you know you need multiplication to calculate it.

The simplest program would use a for loop, something like
  1. long fact = 1;
  2. // request is the number of which the factorial is requested
  3. for (int i=1; i<=request; fact *= i++);

I'm not sure why you'd want to use overloaded operators, I guess you have to make a class Factorial.
If that's so the operator seems simple, with a body like "return f*i;" where f is a class member and i the parameter to the operator.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC