本文概述
- 建议:在继续解决方案之前, 请先在{IDE}上尝试使用你的方法。
- C ++
- Java
- Python3
- C#
- 的PHP
文章图片
和售价为
文章图片
产品。任务是计算应用于该产品的折扣百分比。
例子:
Input: M = 120, S = 100Output: 16.66%Input: M = 1000, S = 500Output: 50%
推荐:请尝试以下方法{IDE}首先, 在继续解决方案之前。 计算产品折扣率的数学公式为:
Discount = Marked Price - Selling priceTherefore, Discount Percentage = (Discount / Marked Price) * 100
以下是查找产品折扣百分比的程序:
C ++
// CPP Program to find the Discount Percentage#include <
bits/stdc++.h>
using namespace std;
// Function to find the Discount Percentage
float discountPercentage( float S, float M)
{
// Calculating discount
float discount = M - S;
// Calculating discount percentage
float disPercent = (discount / M) * 100;
return disPercent;
}// Driver code
int main()
{
int M, S;
M = 120;
S = 100;
// Setting the precision to 2 decimals
cout <
<
std::fixed <
<
std::setprecision(2)
<
<
discountPercentage(S, M) <
<
"%" <
<
endl;
M = 1000;
S = 500;
// Setting the precision to 2 decimals
cout <
<
std::fixed <
<
std::setprecision(2)
<
<
discountPercentage(S, M) <
<
"%" <
<
endl;
return 0;
}
Java
// Java Program to find the Discount Percentageimport java.util.*;
import java.lang.*;
import java.io.*;
class GFG{// Function to find the Discount Percentage
static float discountPercentage( float S, float M)
{
// Calculating discount
float discount = M - S;
// Calculating discount percentage
float disPercent = (discount / M) * 100 ;
return disPercent;
}// Driver code
public static void main(String args[])
{
int M, S;
M = 120 ;
S = 100 ;
System.out.printf( "%.2f" , discountPercentage(S, M));
System.out.println( "%" );
M = 1000 ;
S = 500 ;
System.out.printf( "%.2f" , discountPercentage(S, M));
System.out.println( "%" );
}
}
Python3
# Python3 Program to find the
# Discount Percentage# Function to find the
# Discount Percentage
def discountPercentage(S, M):# Calculating discount
discount = M - S# Calculating discount percentage
disPercent = (discount / M) * 100return disPercent# Driver code
if __name__ = = '__main__' :
M = 120
S = 100print (discountPercentage(S, M), "%" )M = 1000
S = 500print (discountPercentage(S, M), "%" )# This code is contribute
# by ihritik
C#
// C# Program to find the
// Discount Percentage
using System;
class GFG
{// Function to find the
// Discount Percentage
static float discountPercentage( float S, float M)
{
// Calculating discount
float discount = M - S;
// Calculating discount percentage
float disPercent = (discount / M) * 100;
return disPercent;
}// Driver code
static public void Main ()
{
int M, S;
M = 120;
S = 100;
Console.Write(discountPercentage(S, M));
Console.WriteLine( "%" );
M = 1000;
S = 500;
Console.Write(discountPercentage(S, M));
Console.Write( "%" );
}
}// This code is contributed by Raj
的PHP
<
?php
// PHP Program to find the
// Discount Percentage// Function to find the
// Discount Percentage
function discountPercentage( $S , $M )
{
// Calculating discount
$discount = $M - $S ;
// Calculating discount percentage
$disPercent = ( $discount / $M ) * 100;
return $disPercent ;
}// Driver code
$M ;
$S ;
$M = 120;
$S = 100;
echo discountPercentage( $S , $M ), "%" , "\n" ;
$M = 1000;
$S = 500;
echo discountPercentage( $S , $M ), "%" , "\n" ;
// This code is contribute
// by inder_verma
?>
输出如下:
16.67%50.00%
推荐阅读
- Python程序(如何在列表中打印偶数())
- 安全电子交易(SET)协议详细指南
- python中的numpy.sum()用法详细介绍
- PHP mysqli_connect()函数用法详细介绍
- C++中的std::min_element解析和用法介绍
- JavaScript模块实现方式代码示例
- PHP |日期和时间用法介绍
- 加入游戏线人和MinnMax的《 2020年额外生命》
- 雨林木风win7纯净重装到U盘图文详细教程图解