答案:

  1. 在函数fun前面加上返回值类型float和函数名fun。

  2. 在函数fun中加上return语句,将计算出的y值返回。

  3. 在主函数中调用fun函数时,将x作为实参传递给fun函数。

  4. 在主函数中调用fun函数时,将x+1作为实参传递给fun函数。

修改后的程序如下:

#include "stdio.h"

float fun(float x) { float y; y = x * x - 2 * x + 6; return y; }

int main() { float x, y1, y2; scanf("%f", &x); y1 = fun(x); y2 = fun(x + 1); printf("y1=%f, y2=%f \n", y1, y2); return 0; }

以下程序中函数fun的功能是计算 的值主函数中调用fun函数计算和的值。#include stdioh 1 float funfloat x float y; y=xx-2x+6; 2 ;int main float xy1y2; scanff&x; y1=fun 3 ;

原文地址: https://www.cveoy.top/t/topic/eEGq 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录