c语言 8-7

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

c语言 8-7

 

 

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

 

上一篇:react异常 Each child in a list should have a unique “key” prop


下一篇:Cypress web自动化12-父子元素定位