#include
int main(void)
{
int electric,money;
printf("请输入用电量:");
scanf("%d",&electric);
if(electric<=50)
{
money=electric*0.53;
}
else
{
money=50*0.53+(0.53+0.05)*(electric-50);
}
printf("电费:%d元\n",money);
return 0;
}
楼主你好,以下是我编的程序,附上编译正确的图片,希望对你有帮助。
#include
int main(void) {
int n;
float cost;
scanf("%d", &n);
if (n > 50) cost = 50 * 0.53 + (n - 50) * 0.58;
else if (n >= 0) cost = n * 0.53;
else cost = -1;
if (cost >= 0) printf("cost = %.2f", cost);
else printf("Invalid Value!\n");
return 0;
}
如果对你有帮助,请采纳,谢谢!
C语言程序:
#include
void main()
{
double power; /* 耗电量 */
double fee; /* 电费 */
printf("请输入月用电量(千瓦时):");
scanf("%lf", &power);
if(power <= 50)
{
fee = 0.53 * power;
}
else
{
fee = 0.53 * 50 + (power - 50) * (0.53 + 0.05);
}
printf("应支出电费:%lf\n", fee);
}
运行测试:
请输入月用电量(千瓦时):60
应支出电费:32.300000
#include
#include
printf("输入用电量:\n");
scanf("%d",&n);
if(n<=50)
printf("应缴电费为%.1f元.",50*0.53);
else printf("应缴电费为%.1f元.",50*0.53+(n-50)*0.58);
}