小乐乐学会了自定义函数,BoBo老师给他出了个问题,根据以下公式计算m的值。
其中 max3函数为计算三个数的最大值,如: max3(1, 2, 3) 返回结果为3。
#include<stdio.h> int max3(int x,int y,int z) { if(x < y) { x = y; } if(x < z) { x = z; } return x; } int main() { int a =0; int b =0; int c = 0; float m =0.00f; scanf("%d %d %d",&a,&b,&c); int ret0 = max3(a+b,b,c); int ret1 = max3(a,b+c,c); int ret2 = max3(a,b,b+c); m = 1.0*ret0/(ret1+ret2); printf("%.2f",m); }
#include <stdio.h> //三个数求最大数 int max3(int x,int y,int z){ int max=0; if (x>y) { max=x; } else { max=y; } if(max>z){ } else { max=z; } return max; } //代入公式输出 int main() { int a, b,c;double m; scanf("%d %d %d",&a,&b,&c); m=(double)max3(a+b,b,c)/(max3(a,b+c,c)+max3(a,b,b+c)); printf("%.2f",m); return 0; }
#include <stdio.h> //找最大的数的函数 int max(int x, int y, int z) { int max = x; if(x < y) { max = y; if(y < z) max = z; } if(x < z) { max = z; if(z < y) max = y; } return max; } //求公式的函数,max1*1.0是把整数转为浮点数 float fun(int max1,int max2, int max3) { return max1*1.0/(max2 + max3); } int main() { int a,b,c; scanf("%d %d %d", &a, &b, &c); //以函数的返回值作为其他函数参数值, printf("%.2f",fun(max(a+b,b,c), max(a,b+c,c), max(a,b,b+c)) ); //以下是详写 // int max1 = max(a+b,b,c); // int max2 = max(a,b+c,c); // int max3 = max(a,b,b+c); // float m = fun(max1,max2,max3); // printf("%.2f", m); return 0; }
#include <stdio.h> int max(int a,int b,int c) { return ((a>b?a:b)>c)?(a>b?a:b):c; } int main() { int a=0; int b=0; int c=0; scanf("%d %d %d",&a,&b,&c); float m=1.0*max(a+b,b,c)/(max(a,b+c,c)+max(a,b,b+c)); printf("%.2f",m); return 0; }
#include <stdio.h> int Max(int x, int y, int z) { int max = x; max = max > y ? max : y; max = max > z ? max : z; return max; } int main() { int a = 0; int b = 0; int c = 0; float result = 0.0f; scanf("%d%d%d", &a, &b, &c); result = (float)Max(a + b, b, c) / (Max(a, b + c, c) + Max(a, b, b + c)); printf("%.2f\n", result); return 0; }
#include <stdio.h> int max3(int num_1, int num_2, int num_3){ int max = num_1; max = num_2>max ? num_2 : max; max = num_3>max ? num_3 : max; return max; } int main() { int a, b, c; scanf("%d %d %d", &a, &b, &c); float m; m = (float)max3(a+b, b, c)/(max3(a, b+c, c) + max3(a, b, b+c)); printf("%.2f", m); return 0; }
#include <stdio.h> int max3(int a, int b, int c) { int max = a; if (b > max) max = b; if (c > max) max = c; return max; } int main() { int a, b, c = 0; scanf("%d %d %d", &a, &b, &c); float m = ((float)max3(a+b,b,c)/(max3(a,b+c,c)+max3(a,b,b+c))); printf("%.2f\n",m); return 0; }
#include <stdio.h> float max3(int x,int y,int z) { int tmp = 0; tmp = x>y?x:y; tmp = tmp>z?tmp:z; return tmp; } int main() { int a,b,c; scanf("%d %d %d",&a,&b,&c); float ret = max3(a+b,b,c); float rer = max3(a,b+c,c); float ree = max3(a,b,b+c); float m = 0.0; m = ret/(rer+ree); printf("%.2f",m); return 0; }
#include <stdio.h> double max3(int a, int b, int c) { // 设a为最大值 int max = a; if (max < b) max = b; if (max < c) max = c; return max; } int main() { int a, b, c; double res = 0; while (scanf("%d %d %d", &a, &b, &c) != EOF) { res = max3(a + b, b, c) / (max3(a, b + c, c) + max3(a, b, b + c)); printf("%.2lf\n", res); } return 0; }
#include<stdio.h> int max3(int a, int b, int c) { int m = a > b ? a : b; m = m > c ? m : c; return m; } int main() { int a, b, c; scanf("%d %d %d", &a, &b, &c); float ret = max3(a + b, b, c) * 1.0 / (max3(a, b + c, c) + max3(a, b, b + c)); printf("%.2f\n", ret); return 0; }
#define _CRT_SECURE_NO_WARNINGS 1 #include<stdio.h> float max3(float x, float y, float z) { if (x >= y && x >= z) return(x); else if (y >= x && y >= z) return(y); else if (z >= x && z >= y) return(z); else return 0; } int main() { float a = 0.0; float b = 0.0; float c = 0.0; scanf("%f %f %f", &a, &b, &c); float sum1 = max3(a + b, b, c); float sum2 = max3(a, (b + c), c) + max3(a, b, (b + c)); float sum3 = sum1 / sum2; printf("%.2f\n",sum3); return 0; }
#include <stdio.h> float max3(float a, float b, float c) { float m; m = a; if(m < b) m = b; if(m < c) m = c; return m; } int main() { float a, b, c; float m; scanf("%d %d %d", &a, &b, &c); m = max3(a+b, b, c)/(max3(a, b+c, c)+max3(a, b, b+c)); printf("%.2f", m); return 0; }
#include<stdio.h> int max3(int x, int y, int z) { int max=x; if (y> max) max = y; if (z > max) max = z; return max; } int main() { int a, b, c; float m,m1, m2, m3; scanf("%d %d %d", &a, &b, &c); m1 = max3(a + b, b, c); m2 = max3(a, b + c, c); m3 = max3(a, b, b + c); m=m1/(m2+m3); printf("%.2f\n", m); }
#include <stdio.h> int max3(int a, int b, int c) { return (a > b ? a : b) > c ? (a > b ? a : b) : c; } int main() { int a = 0; int b = 0; int c = 0; scanf("%d%d%d", &a, &b, &c); float val = 0.0f; val = 1.0 * max3(a + b, b, c) / (max3(a, b + c, c) + max3(a, b, b + c)); printf("%.2f\n", val); return 0; }