#include <iostream> float average();//主函数在前需要申明 int main() { float x; x = average(); printf("平均值为:%5.2f\n", x); return 0; } float average() { float x1, x2, x3, x4, x5; printf("请输入五个数:"); scanf_s("%f%f%f%f%f", &x1, &x2, &x3, &x4, &x5); return((x1 + x2 + x3 + x4 + x5) / 5); }。
#include <iostream> float average(float x1, float x2, float x3, float x4, float x5) { return((x1 + x2 + x3 + x4 + x5) / 5); } int main() { float a,a1,a2,a3,a4,a5; printf("请输入五个数:"); scanf_s("%f%f%f%f%f", &a1, &a2, &a3, &a4, &a5); a = average( a1,a2,a3,a4,a5); printf("平均值为:%5.2f\n", a); return 0; }
标签:函数,float,f%,x2,x3,x1,x4,语言 From: https://www.cnblogs.com/zqyqz/p/17467659.html