What would you like to do?

# How do you write a C program to calculate the factorial of given no?

Would you like to merge this question into it?

#### already exists as an alternate of this question.

Would you like to make it the primary and merge this question into it?

#### exists and is an alternate of .

// Iterative solution
unsigned long iterativeFactorial(const unsigned long n) {

unsigned long i, factorial = 1;
for(i = 1; i <= n; i++) {
factorial *= i;
}

return factorial;

}

// Recursive solution
unsigned long recursiveFactorial(const unsigned long n) {

if(n <= 1) {
return n;
}

return n * recursiveFactorial(n - 1);

}

// Sample calls
int main() {

unsigned long n;
printf("Enter a number to find its factorial: ");
scanf("%u",&n);

printf("Iterative factorial: %u\n", iterativeFactorial(n));
printf("Recursive factorial: %u\n", recursiveFactorial(n));

return 0;

}
17 people found this useful
Thanks for the feedback!

# How do you write a program that calculate factorial?

include #include void main() { clrscr(); int i=1,fact=1,n; printf("enter a no."); scanf("%d"n); while(i

# How to write a C program to find factorial of given integer using recursive function?

// Note: You may need a larger data type, factorials become very big very quickly and may cause an overflow long factorial(int x) { if(x == 1) return 1; return((long)

# What is a program in c to calculate factorial of number?

First of all we will define what factorial is and how to it is calculated. Factional is non negative integer. Notation would be n! It is calculated by multiplying all intege

# How do you write a C program that calculates parking charges for a given day?

#include   minfee = 2;   int main()  {  int car1,car2,car3,hour,hour2,hour3,charge1,charge2,charge3,  totalhour,totalcharge,minfee; 

# Write a C program to calculate factorial of given positive integer no?

include long double fact (long double n) { return (n == 1) ? 1 : n * fact(n-1); } void main() { int n; printf("Enter a number:\\n>"); scanf("%d",&n); printf("%

# Write a c program to print factorial of given number and using do while loop?

include #include void main() { int n,i,fact=1; clrscr(); printf("enter the value of n:"); Scanf("%d",&n); for(i=1;i

# How can you write a program in c language to calculate factorial of 100 or above that?

  The largest factorial in a 32 bit unsigned integer is 12!, which is 479,001,600. The largest factorical in a 64 bit unsigned integer is 20!, which is 2,432,902,008,176,6

# Write a C program to find the factorial of a given number?

This program will compute N Factorial for any N, and does not suffer from overflow, because it uses a bin technique and handles each digit individually. For large values of N,

# Write a C program to calculate a factorial?

include   #include   void main()   {   int a,b,c=1;   clrscr();   {   printf("enter the number b=");   scanf("%d",&b);   }   for(a=b;a>

# How do you write a c program to calculate factorial using recursion?

unsigned long nfact(int n) if (n2) return n else return n*nfact(n-1); For 32-bit integers, this program will fail at N13, due to overflow. For 64-bit integers, it will fail at

# How do you write a C program to calculate the factorial within recursive function?

Note: This fails at N=20 due to truncation error #include #define FALSE (0) #define TRUE (1) } /* Microsoft 64-bit recursive */ unsigned long long NFactLongLongRecursive (

# How do you write a program that calculate factorial in javascript?

function factorial(n) { var x=1; while(n>1) x*=(n--); return x; }

# Write a C program to calculate the factorial of a given number using functions?

include int fact(int x); int main() { int x, total; printf("Enter a number: "); scanf("%d", &x); total = fact(x); printf("The factorial of %d is %d", x, total

# Write a program to calculate the factorial of a given number?

/*this is the program to find the factorial to n numbers*/ #include void main() { int n,f,factorial(int); printf("which number facrorial you want?"); scanf("%d",&n

# How do you write a C program to find factorial of given integer using function?

There are several methods, some recursive, and iterative. Most suffer from lack of precision, because factorials get large fast. Here is a routine that compares various method

# Write a program in c plus plus to compute the factorial of a given number?

The factorial of a real number, n, is the product of all positive real numbers less than or equal to n, denoted as n!. Thus, 5! = 5*4*3*2*1 = 120. Computing factorials is a n

# How do you write a c program to calculate the SUM and COUNT of Primes from a given range of numbers?

To get complete tutorials of "c programming"   Reference:programming-bd.com/c_page2.aspx# prime number