首页 > 编程语言 > 详细

c语言 8-7

时间:2021-05-23 09:16:17      阅读:26      评论:0      收藏:0      [点我收藏+]

1、

#include <stdio.h>

int fac(int x)
{
    if(x > 0)
        return x * fac(x - 1);
    else
        return 1; 
}

int main(void)
{
    int a, b;
    puts("please input two integers.");
    printf("a = "); scanf("%d", &a);
    printf("b = "); scanf("%d", &b);
    
    printf("result:  %d\n", fac(a)/(fac(b)*fac(a - b)));
    
    return 0;
}

技术分享图片

 

 

2、

#include <stdio.h>

int fac(int x)
{
    if(x > 0)
        return x * fac(x - 1);
    else
        return 1;
}

int main(void)
{
    int a, b;
    puts("please input two integers.");
    do
    {
        printf("a = "); scanf("%d", &a);
        if(a < 0)
        {
            puts("the range of a >= 0.");
            continue;
        }
        printf("b = "); scanf("%d", &b);
        if(b < 0)
        {
            puts("the range of b >= 0.");
            continue;
        }
        if(a < b)
            puts("a should >= b.");
    }
    while( a < b || a < 0 || b < 0);
    
    puts("==========\n");
    printf("the result: %d\n", fac(a)/(fac(b) * fac(a - b)));
    
    return 0;
}

技术分享图片

 

c语言 8-7

原文:https://www.cnblogs.com/liujiaxin2018/p/14800163.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!