您的位置:首页 > 其它

C primer plus 第九章 练习5:

2016-05-30 10:52 176 查看
/*
==========================================================
编写并测试函数larger_of(),其功能是两个double类型变量的
数值替换成他们中的较大值。例如,larger_of(x,y)会把x和Y中较
大树枝重新赋给变量x和y。
==========================================================
*/

#include <stdio.h>
void larger_of(double * x, double * y);
int main(void)
{
double x, y;

printf("Please input two double: \n");
while((scanf_s("%lf %lf", &x, &y)) == 2.00)
{
larger_of(&x, &y);
printf("now x is %g, y is %g.\n\n", x, y);
printf("Please input two double: \n");
}
return 0;
}

void larger_of(double *x, double *y)
{
if (*x > *y)
*y = *x;
else
*x = *y;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: