|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #include <stdio.h>
- /*
- * C语言实现,三个数中找出最大最小的数。
- * 最后两个参数是由变量传递过去作为返回值
- */
- void if_else_Judge_MaxMin(int x, int y, int z, int *rtMax, int *rtMin)
- {
- *rtMin = *rtMax = x;
- if ( y > *rtMax )
- {
- *rtMax = y;
- }
- else if ( y < *rtMin )
- {
- *rtMin = y;
- }
- if ( z > *rtMax )
- {
- *rtMax = z;
- }
- else if ( z < *rtMin )
- {
- *rtMin = z;
- }
- }
- void operator_Judge_MaxMin(int x, int y, int z, int *rtMax, int *rtMin)
- {
- *rtMax = x > y ? x : y;
- *rtMax = *rtMax > z ? *rtMax : z;
- *rtMin = x < y ? x : y;
- *rtMin = *rtMin < z ? *rtMin : z;
- }
- int main(int argc, char *argv[])
- {
- int x, y, z,
- Max = -1, Min = -1;
- printf("input three number\n");
- printf("input: ");
- scanf("%d %d %d", &x, &y, &z);
- operator_Judge_MaxMin(x, y, z, &Max, &Min);
- // if_else_Judge_MaxMin(x, y, z, &Max, &Min);
- printf("Max: %d\tMin: %d\n", Max, Min);
- return 0;
- }
复制代码 |
|