Code tính n giai thừa trong C

Code: C 19/02/2021 07:43

//Code chuong trinh tinh giai thua
#include <stdio.h>
double GT(double n){
	
	printf("%.lf", n);
	
	if(n > 1){
		printf(" * ");
		return n * GT(n - 1);
	} 
		return 1.0;
	 	
}
void main(){
	double n;
	printf("Nhap vao 1 so n = ");
	scanf("%lf", &n);
	printf("%.lf! = ", n);
	
	double kq =  GT(n);
	printf("\n%.lf! = %.0lf",n,kq);
}