

 Thread Tools  Search this Thread 
#1
 
 
How to calculate factorial of a number in C++ I am having problem coding in C++. I want to calculate the factorial of a number that the user inputs but the problem is that whatever logic I try to do, it fails. So I am here to know what are the possibilities and how do you calculate factorial of a user specified number in C++? 
#2
 
 
Re: How to calculate factorial of a number in C++ You can calculate the factorial of a number in C++ using an external function as below and calling that function in your main code: Code: int calfactorial (int x) { int finalx = 1; if (x==1) return 1; for (int i = 1; i <= x; ++i) finalx = finalx * i; return finalx; }
__________________ Grand Theft Auto 4 PC Video Game 
#3
 
 
Re: How to calculate factorial of a number in C++ Here is how factorial is calculated in C++: Code: # include <iostream.h> int factorial (int); int main() { int result; cout << "Enter your number: "; cin >> result; cout << "Factorial of " << result << "is "<< factorial (result) << endl; } int factorial (int n) { int fact = 1; if (n <= 1) return 1; else fact = n * factorial (n  1); return fact; } 

Tags: factorial 
Thread Tools  Search this Thread 

Similar Threads for: "How to calculate factorial of a number in C++"  
Thread  Thread Starter  Forum  Replies  Last Post 
How to create factorial of numbers using sub procedure in vbscript  Gurseerat  Software Development  1  04022012 12:21 PM 
n factorial program in C  MaryJ  Software Development  5  24092010 09:59 PM 
c# program for factorial  roodiii  Software Development  5  19122009 02:42 PM 
How to write java program to find factorial of number?  Balamohan  Software Development  5  28112009 10:14 PM 
What is the Program to findout factorial of given number?  Sheenas  Software Development  5  27112009 01:42 PM 