- UID
- 2129
- 帖子
- 4614
- 精华
- 0
- 贡献
- 2
- 推广
- 0
- 有效BUG
- 0
- 注册时间
- 2005-8-8
|
原程序是比较两个数的大小,代码如下
# include <stdio.h>
int maxValue(int, int); /*函数声明*/
main( )
{
int x, y, z;
printf("Enter 2 integers:");
scanf("%d%d", &x, &y);
z = maxValue(x,y);
printf("The larger value is %d.",z);
}
int maxValue(int x, int y)
{
int max;
if (x<y)
max=x;
else
max=y;
return max;
}
我把它成功改写成比较三个数的大小,代码如下
# include <stdio.h>
int maxValue(int, int, int); // 函数声明
int main()
{
int x, y, z, o;
printf("Enter 3 integers:");
scanf("%d%d%d", &x, &y, &o);
z = maxValue(x, y, o);
printf("The larger value is %d.", z);
}
int maxValue(int x, int y, int o)
{
int max;
if (x > y, x > o)
max = x;
else if (o > x, o > y)
max = o;
else
max = y;
return max;
} |
|