如果售价大于成本价,则寻找利润的公式如下:
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