Program to calculate GST from original and net prices
Last Updated :
20 Feb, 2023
Given Original cost and Net price then calculate the percentage of GST
Examples:
Input : Netprice = 120, original_cost = 100
Output : GST = 20%
Input : Netprice = 105, original_cost = 100
Output : GST = 5%
How to calculate GST
GST ( Goods and Services Tax ) which is included in netprice of product for get GST % first need to calculate GST Amount by subtract original cost from Netprice and then apply
GST % formula = (GST_Amount*100) / original_cost
Netprice = original_cost + GST_Amount
GST_Amount = Netprice – original_cost
GST_Percentage = (GST_Amount * 100)/ original_cost
C++
#include <iostream>
using namespace std;
float Calculate_GST( float org_cost, float N_price)
{
return (((N_price - org_cost) * 100) / org_cost);
}
int main()
{
float org_cost = 100;
float N_price = 120;
cout << "GST = "
<< Calculate_GST(org_cost, N_price)
<< " % " ;
return 0;
}
|
Java
import java.io.*;
class GFG
{
static float Calculate_GST( float org_cost,
float N_price)
{
return (((N_price - org_cost) * 100 )
/ org_cost);
}
public static void main (String[] args)
{
float org_cost = 100 ;
float N_price = 120 ;
System.out.print( " GST = " + Calculate_GST
(org_cost, N_price) + "%" );
}
}
|
Python3
def Calculate_GST(org_cost, N_price):
return (((N_price - org_cost) * 100 ) / org_cost);
org_cost = 100
N_price = 120
print ( "GST = " ,end = '')
print ( round (Calculate_GST(org_cost, N_price)),end = '')
print ( "%" )
|
C#
using System;
class GFG
{
static float Calculate_GST( float org_cost,
float N_price)
{
return (((N_price - org_cost) * 100)
/ org_cost);
}
public static void Main ()
{
float org_cost = 100;
float N_price = 120;
Console.Write( " GST = " + Calculate_GST
(org_cost, N_price) + "%" );
}
}
|
PHP
<?php
function Calculate_GST( $org_cost , $N_price )
{
return ((( $N_price - $org_cost ) *
100) / $org_cost );
}
$org_cost = 100;
$N_price = 120;
echo ( "GST = " );
echo (Calculate_GST( $org_cost , $N_price ));
echo ( " % " );
?>
|
Javascript
<script>
function Calculate_GST(org_cost , N_price) {
return (((N_price - org_cost) * 100) / org_cost);
}
var org_cost = 100;
var N_price = 120;
document.write( " GST = " + Calculate_GST(org_cost, N_price) + "%" );
</script>
|
Output:
GST = 20%
Time Complexity: O(1)
Auxiliary Space: O(1)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...