代码如下:

#include <stdio.h>

int main() { int num; // 水果编号 float weight; // 重量 float price; // 单价 float total; // 总价

printf("请输入水果编号和重量(空格隔开):");
scanf("%d %f", &num, &weight);

switch (num)
{
    case 1:
        price = 2.0;
        break;
    case 2:
        price = 2.5;
        break;
    case 3:
        price = 3.0;
        break;
    case 4:
        price = 4.5;
        break;
    default:
        printf("输入的水果编号有误!\n");
        return 0;
}

total = weight * price;
printf("应付款为:%.2f元\n", total);

return 0;

}

c语言以下4种水果1苹果2梨3桔子4芒果单价分别是20元公斤25元公斤30元公斤45元公斤请输入水果编号、重量计算应付款

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

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