编写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 恩师诗词祝福语简短大全