定义一个函数,从给定的三个整数中返回最大值,并在主函数中试验此函数.

学习 时间:2026-04-03 09:32:40 阅读:2146
定义一个函数,从给定的三个整数中返回最大值,并在主函数中试验此函数.提示:1.先定义求三个数中最大值的函数.考虑返回值、参数数量.逻辑用if语句实现; 2.在主函数中要求用户输入三个数; 3.调用定义的函数求最大值并显示出来.注意人机对话要清晰.

最佳回答

动听的飞机

精明的萝莉

2026-04-03 09:32:40

用C语言写:#include int max(int a,int b,int c); void main() { int a,b,c,m; printf("请输入第一个数的值:\n"); scanf("%d",&a); printf("请输入第二个数的值:\n"); scanf("%d",&b); printf("请输入第三个数的值:\n"); scanf("%d",&c); m=max(a,b,c); printf("这三个数的最大值是:%d\n",m); } int max(int a,int b,int c) { if(a>b && a>c) return a; else if(b>a && b>c) return b; else return c; }

最新回答共有2条回答

  • 雪白的帅哥
    回复
    2026-04-03 09:32:40

    用C语言写:#include int max(int a,int b,int c); void main() { int a,b,c,m; printf("请输入第一个数的值:\n"); scanf("%d",&a); printf("请输入第二个数的值:\n"); scanf("%d",&b); printf("请输入第三个数的值:\n"); scanf("%d",&c); m=max(a,b,c); printf("这三个数的最大值是:%d\n",m); } int max(int a,int b,int c) { if(a>b && a>c) return a; else if(b>a && b>c) return b; else return c; }

上一篇 英语音标 z 发什么音?

下一篇 18乘8.7等于多少