编写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
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短