944,001 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 17907
  • C++ RSS
Nov 15th, 2004
0

program for finding factorial of a number using *operator overloading

Expand Post »

can you please help me in writing a program(c++) for finding factorial of a number using * operator overloading?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
suma2411 is offline Offline
1 posts
since Nov 2004
Nov 15th, 2004
0

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

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
C++ Syntax (Toggle Plain Text)
  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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: unresolved external symbol when using a hashtable class
Next Thread in C++ Forum Timeline: C++ Compilers





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC