Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to write factorial of n in c language
How to write factorial of n in c language

#include

"stdio.h"

main()

{

int

n,i;

double

p=1; //Double is used here instead of Int, because the range of Int is too small

printf ("Please enter a number:");

scanf("%d",& n);

for(i=2; i< =n; i++)

p*=i;

printf("n! shu=%lf\n",p);

}

Extended data:

Find the factorial of 365 with Ruby.

def AskFactorial(num) factorial=1;

step (num, 1) {| I | factorial * = I}

return factorial end factorial = ask factorial (365)

puts factorial

factorial related formula

This formula is often used to calculate various limits related to factorial.

this is a simplified formula of stirling formula.

Baidu encyclopedia-factorial