answersLogoWhite

0


Best Answer

/* gcc -ansi -Wall -Wextra -pedantic -s -static 0.c -o 0 */

#include <stdio.h>

int main ( )

{

int n , factorial = 1 ;

printf ( "enter the value of n\n") ;

scanf ( "%i" , & n ) ;

while ( n != 0 )

{

factorial *= n ;

n -- ;

}

printf ( "The factorial of n is\n%i\n" , factorial ) ;

return 0;

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

unsigned long factorial(unsigned long n) {

if (n = 2) return n else return n * factorial(n - 1);

} This is a recursive approach. Note very carefully that it will fail when the range of an unsigned long is exceeded. In a 32-bit environment, the maximum value of an unsigned long is 4,294,967,296, and the maximum value of n in this case is 12. The factorical of 12 is 479,001,600, which fits, but the factorial of 13 is 6,227,020,800, which does not fit. You could go unsigned long long (a 64-number), if you platform supports it, which would give you a maximum factorial of 20, which is 2,432,902,008,176,640,000. Anything larger, and you need an arbitrary precision decimal multiplier. You could implement this with linked lists.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

#include <iostream>

#include <cctype>

using std::cin;

using std::cout;

using std::endl;

using std::tolower;

long factorial(const int& N);

int main()

{

int N = 0; //factorial of N

char command = 'n';

do

{

cout << "Enter a number to calculate factorial: ";

cin >> N;

cout << endl << "Factorial of " << N << " is: " << factorial(N) << endl;

cout << "Do you want to continue (y/n)?";

cin >> command;

cout << endl;

} while ('y' 0)

{

return 1;

}

else

{

return (N * factorial(N - 1));

}

}

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

int main() { // Variable declarations. unsigned long int factorial = 1 , number = 1; // reads a number for finding its factorial. cout << "Input a non-negative number: "; cin >> number; while( number > 1 ) { factorial *= number * ( number - 1 ); number -= 2; } cout << "Factorial is: " << factorial << endl; system("PAUSE"); return 0;

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

#include <iostream>

using namespace std;

int fact(int x);

int main()

{

int x, total;

cout << "Enter a number: ";

cin >> x;

total = fact(x);

cout << "The factorial of " << x << " is: " << total << endl;

char wait;

cin >> wait;

return 0;

}

int fact(int x)

{

if(x == 1)

{

return 1;

}

return fact(x - 1) * x;

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

void main()

{

int i,b=1,n;

printf("enter the number:");

scanf("%d",&n);

for(i=n;i<=n;i--)

b=b*i;

printf("factorial number is:%d",b);

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

/*this is the program to find the factorial to n numbers*/

#include<stdio.h>

void main()

{

int n,f,factorial(int);

printf("which number facrorial you want?");

scanf("%d",&n);

f=factorial(n);

printf("The factorial upto %d is %d",n,f);

}

int factorial(int a)

{

if(a==0)

return 1;

else

return (a)*factorial(a-1);

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write the program that display the factorial of a number?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write the Pseudocode to find the factorial of a number?

Pseudo code+factorial


Write a program to display the name of days when a user enters a number?

write a program to display your name age class schoolname e-mail 2hobby based on choice


7 Write a C program to compute the factorial of a number using for loop?

int factorial(int n) { int i; int f=1; for(i=2;i&lt;=n;++i) f*=i; return f; }


Write a program which takes any number of days from the user the program should display the number of years number of months formed by these days as well as the remaining days?

Write a program which takes any number of days from the user. the program should display the number of years, number of months formed by these days as well as the remaining days.


Write a program using while loop?

//program to find the factorial value f any number using while loop #include&lt;stdio.h&gt; void main() { int i,n,fact=1; printf("Enter the number\n"); scanf("%d",&amp;n); i=n; while (i&gt;=1) { fact=fact*i; i--; } printf("The factorial value=%d",fact); } the above is a program for calculating tha factorial value of any number which is entered by the user


Write a java script program to print first ten odd natural numbers in C?

Q.1 Write a program to print first ten odd natural numbers. Q.2 Write a program to input a number. Print their table. Q.3 Write a function to print a factorial value.


1.Write a c program for Fibonacci series?

/*program to calculate factorial of a number*/ #include&lt;stdio.h&gt; #include&lt;conio.h&gt; void main() { long int n; int a=1; clrscr(); printf("enter the number="); scanf("%ld",&amp;n); while(n&gt;0) { a*=n; n--; } printf("the factorial is %ld",a); getch(); }


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

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


Write this expression as a factorial 87654321?

That's not the factorial of any number. For a start, the factorial of any number greater than or equal to 2 is even, because of the factor 2. The factorial of any number greater or equal to five ends with 0. Another answer: I suspect the questioner meant to ask how to write 8*7*6*5*4*3*2*1 as a factorial. If so, then the answer is "8!"


Write a program in shell script to display odd number from 0 to 100?

seq 1 2 99


How can I write a program to display prime numbers from 1 to 100?

Write a function that implements an algorithm that checks to see if a particular integer is prime (returning a boolean). Write a program that uses that function on each number from 1 to 100, and if true, displays that number.


Write a recursive procedure to compute the factorial of a number?

#include &lt;iostream&gt; using namespace std; int main() { int i, number=0, factorial=1; // User input must be an integer number between 1 and 10 while(number&lt;1 number&gt;10) { cout &lt;&lt; "Enter integer number (1-10) = "; cin &gt;&gt; number; } // Calculate the factorial with a FOR loop for(i=1; i&lt;=number; i++) { factorial = factorial*i; } // Output result cout &lt;&lt; "Factorial = " &lt;&lt; factorial &lt;&lt; endl;