浙大版《C语言程序设计(第3版)》题目集 习题2-2 阶梯电价 (15分)

在这里插入图片描述

#include <stdio.h>
int main()
{
    float n, cost;
    scanf("%f", &n);
    if (n > 50)
        cost = (0.53 * 50) + 0.58 * (n - 50);
    else if (n >= 0)
        cost = 0.53 * n;
    else
        cost = -1; //当电费小于0元,用-1作为标记。
    if (cost < 0)
        printf("Invalid Value!");
    else
        printf("cost = %.2f", cost);
    return 0;
}
发布了161 篇原创文章 · 获赞 117 · 访问量 6026

猜你喜欢

转载自blog.csdn.net/qq_44458489/article/details/105281163