在C語言中,可以通過以下方式調(diào)用fact函數(shù):
#include <stdio.h>
// 聲明fact函數(shù)
int fact(int n);
int main() {
int num = 5;
int result = fact(num); // 調(diào)用fact函數(shù)
printf("Factorial of %d is %d\n", num, result);
return 0;
}
// 定義fact函數(shù)
int fact(int n) {
if (n == 0) {
return 1;
} else {
return n * fact(n - 1);
}
}
#include <stdio.h>
// 聲明fact函數(shù)
int fact(int n);
int main() {
int num = 5;
int result = fact(num); // 調(diào)用fact函數(shù)
printf("Factorial of %d is %d\n", num, result);
return 0;
}
// 定義fact函數(shù)
int fact(int n) {
if (n == 0) {
return 1;
} else {
return n * fact(n - 1);
}
}
無論是在同一個(gè)函數(shù)中調(diào)用還是在不同函數(shù)中調(diào)用,都需要先聲明fact函數(shù),再進(jìn)行調(diào)用。