简单C程序没有打印

时间:2015-10-23 11:37:49

标签: c printf return-value

我正在尝试运行这个简单的代码:

#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);   
    }
}

但不知怎的,没有结果出现。能否请您解释一下如何正确实施? 提前谢谢!

1 个答案:

答案 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 );
}