C语言 编译器是DEV
编写函数,求两数的平均值,较大值,较小值 #include <stdio.h>int main()
{
long long a, b;
scanf("%lld%lld", &a, &b);
printf("平均值:%.1f\n较大值:%lld\n较小值:%lld", ((float)(a+b))/2, (a >= b ? a : b), (a <= b ? a : b));
return 0;
} #include<stdio.h>
int max(int, int);
int min(int, int);
float average(int, int);
int main(void) {
int num1 = 10, num2 = 20;
printf("max=%d\n",max(num1,num2));
printf("min=%d\n",min(num1,num2));
printf("average=%f\n",average(num1,num2));
}
int max(int num1, int num2) {
if (num1 > num2) {
//TODO
return num1;
}
return num2;
}
int min(int num1, int num2) {
if (num1 > num2) {
//TODO
return num2;
}
return num1;
}
float average(int num1, int num2) {
printf("%d\n",num1);
printf("%d\n",num2);
float num3=(float)num1;
float num4=(float)num2;
return num3 / num4;
} tommyyu 发表于 2022-11-24 15:47
感谢大佬
homeskating 发表于 2022-11-24 15:51
感谢
页:
[1]