C++程式查詢折扣百分比
在這個問題中,我們得到了兩個數字,它們定義了某個產品的標價 (M) 和售價 (S)。我們的任務是建立一個C++程式來查詢折扣百分比。
折扣是指從產品實際價格(標價)中扣除的金額。
折扣公式為:
discount = marked price - selling price
折扣百分比是從產品實際價格中扣除的價格百分比。
折扣百分比的公式為:
discount percentage = (discount / marked price ) * 100
讓我們舉個例子來理解這個問題:
輸入
240, 180
輸出
25%
解釋
Discount = (240 - 180) = 60 Discount percentage = (60/240)*100 = 25%
解決方案方法
折扣和折扣百分比的公式為:
Discount = marked price - selling price Discount percentage = (discount / marked price ) * 100
程式說明我們解決方案的工作原理:
示例
#include <iostream>
using namespace std;
int main() {
float MP = 130, SP = 120;
float DP = (float)(((MP - SP) * 100) / MP);
printf("The discount percentage on the given product is %.2f\n", DP);
return 0;
}輸出
The discount percentage on the given product is 7.69
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP