4.以下4种水果1苹果2梨3桔子4芒果单价分别是20元公斤25元公斤30元公斤45元公斤请输入水果编号、重量计算应付款。用c语言程序
#include <stdio.h>
int main()
{
int num; //水果编号
float weight; //重量
float price; //价格
printf("请输入水果编号:\n");
scanf("%d", &num);
printf("请输入重量:\n");
scanf("%f", &weight);
switch(num)
{
case 1:
price = 2.0 * weight;
break;
case 2:
price = 2.5 * weight;
break;
case 3:
price = 3.0 * weight;
break;
case 4:
price = 4.5 * weight;
break;
default:
printf("输入有误!\n");
return 0;
}
printf("应付款:%.2f元\n", price);
return 0;
}
原文地址: https://www.cveoy.top/t/topic/Nin 著作权归作者所有。请勿转载和采集!