C primer plus 第九章 练习5:

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

#include 
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;
}

你可能感兴趣的:(练习题)