954,170 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

program for finding factorial of a number using *operator overloading

:D
can you please help me in writing a program(c++) for finding factorial of a number using * operator overloading?

suma2411
Newbie Poster
1 post since Nov 2004
Reputation Points: 10
Solved Threads: 0
 

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

long fact = 1;
// request is the number of which the factorial is requested
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.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You