我正在尝试运行这个简单的代码:
#include <stdio.h>
int main()
{
int n = 3;
printf("Enter your number: ");
scanf("%d",&n);
int faculty(int n){
int i = 1;
int res = 1;
for (i = 2;i<= n;i++){
res = res * i;
}
printf("the value is %d\n",res);
return(0);
}
}
但不知怎的,没有结果出现。能否请您解释一下如何正确实施? 提前谢谢!
答案 0 :(得分:0)
请试试这个:
#include
int faculty( int n )
{
int i = 1;
int res = 1;
for ( i = 2; i <= n; i++ )
{
res = res * i;
}
printf( "the value is %d\n", res );
getchar( );
return ( 0 );
}
int main( )
{
int n = 3;
printf( "Enter your number: " );
scanf( " %d", &n );
faculty( n );
}