c - 简单的 C 程序未打印

标签 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);   
    }
}

但不知怎的,没有显示任何结果。您能解释一下应该如何正确实现吗? 提前致谢!

最佳答案

请尝试这个:

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

关于c - 简单的 C 程序未打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33301386/

相关文章:

c - 多键快速排序崩溃

c - g_hash_table_insert malloc() : memory corruption

c - 如何在第一个 printf 语句后添加一个空格?

Java返回值

c++ - 如何将指针作为迭代器返回?

c - 如何打印二叉树?

embedded - 使用 printf 打印 float/double 会使程序崩溃

c - 打印 0 初始化的数组元素的值什么也打印不出,为什么?

java - 在Eclipse中调试时,我可以在返回之前找出返回值吗?

objective-c - 如何编码和解码 const char *