c语言编程练习题:7-22 用天平找小球
作者:yunjinqi   类别:    日期:2023-05-29 13:18:37    阅读:119 次   消耗积分:0 分    

image.png

#include <stdio.h>

struct ball{
    char *name;
    int value;
};


char compare_balls(struct ball b1,struct ball b2,struct ball b3){
    // 输出三个中不一样的数字
    if (b1.value!=b2.value && b1.value!=b3.value){return *b1.name;}
    if (b2.value!=b1.value && b2.value!=b3.value){return *b2.name;}
    if (b3.value!=b1.value && b3.value!=b2.value){return *b3.name;}
}

int main(void){
    int a,b,c;
    struct ball b1,b2,b3;
    char r;
    if (scanf("%d %d %d",&a,&b,&c)!=0){
        b1.name = "A";
        b1.value = a;
        b2.name = "B";
        b2.value = b;
        b3.name = "C";
        b3.value = c;
        r = compare_balls(b1,b2,b3);
        printf("%c",r);
    }else{
        printf("输入数据存在异常");
    }
    return 0;
}


版权所有,转载本站文章请注明出处:云子量化, http://www.woniunote.com/article/147
上一篇:c语言编程练习题:7-21 超速判断
下一篇:c语言编程练习题:7-23 分段计算居民水费