#include<stdio.h> int main(void) { int m,i; double x,y; /* 定义x为用电量,y为电费 */ double cylinder(double x); printf("请输入m"); scanf_s("%d",&m); for(i=1;i<=m;i++){ printf("请输入电量: "); scanf_s("%Lf",&x); if(x<0){ printf("sorry,您的输入有误"); } else { y=cylinder(x); printf("y=%.3f ",y); } } return 0; } double cylinder(double x) { double y; if(x<=50){ y=0.53*x; } else{ y=50*0.53+(x-50)*0.58; } return y; }