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

factorial

please help me to find how to find the factorial of a number in a easy way?
the methods i have seen are difficult to me .can any one heelp me to solve the problem?

jbstin
Newbie Poster
11 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

Already did -- see the previous thead you started this morning.

Ancient Dragon
Retired & Loving It
Team Colleague
30,046 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,342
 

So...what/where is the method you've tried? Without providing you the answer...here is a basic outline:

#include <iostream>
#include <cctype>
#include <iomanip>
#include <cmath>
#include <fstream>
#include <string>


using namespace std;

int main(void) 
{
int num;//number to get it's factorial
	
cout << "Please enter a positive number: ";
cin >> num;//user enters number
if (num < 0)
{
cout << "That is not a positive number.\n";
}
else
{
cout << num << " factorial is: " << factorial(num) << endl;
}

The above isn't complete nor tested. Also, in the future, before posting, search the forums to see if someone else had the same problem/assignment. We are willing to help, but we don't want to waste time doing the same thing over and over again...In the factorial function, you could try something like this:

int factorial(int ) 
{
int temp;
if(num <= 1) return 1;
//figure out the simple calculaltion
return temp;
}//end for factorial

hope this helps.

zandiago
Nearly a Posting Maven
2,480 posts since Jun 2007
Reputation Points: 129
Solved Threads: 26
 
So...what/where is the method you've tried? Without providing you the answer...here is a basic outline:


I guess you need to learn to read too. Problem already solved in another thread.

Ancient Dragon
Retired & Loving It
Team Colleague
30,046 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,342
 
joshua.tilson
Light Poster
47 posts since Nov 2007
Reputation Points: 13
Solved Threads: 0
 

ok ok...totally missed that one...i didn't see another thread started by jbstin...the title of the threads were different...so i just went right in...my eyes need tested anyways...and AD...i'm not in kindergarden yet...so i can't read too well.

zandiago
Nearly a Posting Maven
2,480 posts since Jun 2007
Reputation Points: 129
Solved Threads: 26
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You