回复 10楼 wengbin
将max设为很小的数这个能理解,但是将max设为要比较的第一个数不知道应该在哪里入手啊,版主大大,求指导
吾道不孤
//三个数字输出最大值 #include <stdio.h> int max(int x,int y,int z) { if(x>y&&x>z) return x; else if(z>y&&z>x) return z; else if(y>x&&y>z) return y; } int main(void) { int a,b,c; scanf("%d,%d,%d",&a,&b,&c); printf("\nThe max number is:%d",max(a,b,c)); getchar(); return 0; }
#include <stdio.h> #include <stdlib.h> #include <conio.h> int main(void) { int value, max_value, min_value, index, result; printf_s("Tips: Input non digit character then <ENTER> to end program.\n\n"); index = 0; do { printf_s("Please input a integer value[%d]: ", index + 1); rewind(stdin); result = scanf_s("%d", &value); if (result == 1) { max_value = (index == 0) ? value : __max(max_value, value); min_value = (index == 0) ? value : __min(min_value, value); ++index; } } while (result == 1); printf_s("\nThe max value is %d\n", max_value); printf_s("The min value is %d\n", min_value); printf_s("\nPress any key to continue..."); _getch(); return EXIT_SUCCESS; }