SHAOXIAOJ正在加载中...

1106: 【实验6.1.2 模块化程序设计】

金币值:2 定数:3 时间限制:1.000 s 内存限制:128 M
解决:20 提交:25 正确率:80.00% 命题人:
点赞量:0 收藏量:0 题目类型:改错题 来源/分类: 函数

题目描述

请修改程序,保证运行正确。

题目代码

#include <stdio.h>
double fact(int n){
    if(n<0) return -1;
    else if(n=0 || n=1)                     /*ERROR*/
        return 1;
    else
      return n*fact(n-1);
}
int main(void){
    int n;
    int result;                              /*ERROR*/
    scanf("%d",&n);
    result=fact(n);
    if(result==-1)
        printf("Please input a number: ");
    else
        printf("The factorial of the number is %lf\n",result);
    return 0;
}

样例输入    复制

9

样例输出    复制

The factorial of the number is 362880.000000