编写C程序以了解购买商品的收益或损失
如果售价大于成本价,则寻找利润的公式如下:
profit=sellingPrice-CosePrice;
如果成本价格大于销售价格,发现损失的公式如下:
loss=CostPrice-SellingPrice
现在,在程序中应用此逻辑,并尝试确定该人在购买任何商品后是否会获利或亏损-
示例
以下是查找损益的C程序-
#include<stdio.h>
int main(){
float CostPrice, SellingPrice, Amount;
printf("\n Enter the product Cost : ");
scanf("%f", &CostPrice);
printf("\n Enter the Selling Price) : ");
scanf("%f", &SellingPrice);
if (SellingPrice > CostPrice){
Amount = SellingPrice - CostPrice;
printf("\n Profit Amount = %.4f", Amount);
}else if(CostPrice> SellingPrice){
Amount = CostPrice - SellingPrice;
printf("\n Loss Amount = %.4f", Amount);
}else
printf("\n No Profit No Loss!");
return 0;
}输出结果执行以上程序后,将产生以下结果-
Enter the Product Cost: 450 Enter the Selling Price): 475.8 Profit Amount = 25.8000
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短