Open In App

Program to calculate GST from original and net prices

Last Updated : 20 Feb, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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++




// CPP Program to compute GST from original
// and net prices.
#include <iostream>
using namespace std;
  
float Calculate_GST(float org_cost, float N_price)
{
    // return value after calculate GST%
    return (((N_price - org_cost) * 100) / org_cost);
}
// Driver program to test above functions
int main()
{
    float org_cost = 100;
    float N_price = 120;
    cout << "GST = "
         << Calculate_GST(org_cost, N_price)
         << " % ";
    return 0;
}


Java




// Java Program to compute GST 
// from original and net prices.
import java.io.*;
  
class GFG 
{
    static float Calculate_GST(float org_cost, 
                                  float N_price)
    {
        // return value after calculate GST%
        return (((N_price - org_cost) * 100
                 / org_cost);
    }
      
    // Driver code
    public static void main (String[] args) 
    {
         float org_cost = 100;
        float N_price = 120;
        System.out.print(" GST = "  + Calculate_GST
                         (org_cost, N_price) + "%");
    }
}
  
// This code is contributed 
// by vt_m.


Python3




# Python3 Program to
# compute GST from original
# and net prices.
  
def Calculate_GST(org_cost, N_price):
  
    # return value after calculate GST%
    return (((N_price - org_cost) * 100) / org_cost);
  
# Driver program to test above functions
org_cost = 100
N_price = 120
print("GST = ",end='')
  
print(round(Calculate_GST(org_cost, N_price)),end='')
  
print("%")
  
# This code is contributed
# by Smitha Dinesh Semwal


C#




// C# Program to compute GST 
// from original and net prices.
using System;
  
class GFG 
{
    static float Calculate_GST(float org_cost, 
                                float N_price)
    {
        // return value after calculate GST%
        return (((N_price - org_cost) * 100) 
                / org_cost);
    }
      
    // Driver code
    public static void Main () 
    {
        float org_cost = 100;
        float N_price = 120;
        Console.Write(" GST = " + Calculate_GST
                        (org_cost, N_price) + "%");
    }
}
  
// This code is contributed 
// by vt_m.


PHP




<?php
// PHP Program to compute GST from 
// original and net prices.
  
function Calculate_GST($org_cost, $N_price)
{
    // return value after calculate GST%
    return ((($N_price - $org_cost) * 
                    100) / $org_cost);
}
  
    // Driver Code 
    $org_cost = 100;
    $N_price = 120;
    echo("GST = "); 
    echo(Calculate_GST($org_cost, $N_price));
    echo(" % ");
  
// This code is contributed 
// by vt_m.
?>


Javascript




<script>
// javascript Program to compute GST 
// from original and net prices.
  
    function Calculate_GST(org_cost , N_price) {
        // return value after calculate GST%
        return (((N_price - org_cost) * 100) / org_cost);
    }
  
    // Driver code
      
        var org_cost = 100;
        var N_price = 120;
        document.write(" GST = " + Calculate_GST(org_cost, N_price) + "%");
  
// This code contributed by aashish1995
  
</script>


Output: 
 

GST = 20%

Time Complexity: O(1)

Auxiliary Space: O(1)



Similar Reads

How to validate GST (Goods and Services Tax) number using Regular Expression
Given string str, the task is to check whether the given string is a valid GST (Goods and Services Tax) number or not using Regular Expression. The valid GST (Goods and Services Tax) number must satisfy the following conditions: It should be 15 characters long.The first 2 characters should be a number.The next 10 characters should be the PAN number
6 min read
Count items common to both the lists but with different prices
Given two lists list1 and list2 containing m and n items respectively. Each item is associated with two fields: name and price. The problem is to count items that are in both the lists but with different prices. Examples: Input : list1[] = {{"apple", 60}, {"bread", 20}, {"wheat", 50}, {"oil", 30}} list2[] = {{"milk", 20}, {"bread", 15}, {"wheat", 4
20 min read
Minimum possible sum of prices of a Triplet from the given Array
Given an array num[] of N integers where each element is associated with a price given by another array price[], the task is to minimize the sum of price by taking a triplet such that num[i] &lt; num[j] &lt; num[k]. If there is no such triplet then print -1. Examples: Input: num[]={2, 4, 6, 7, 8}, price[]={10, 20, 100, 20, 40} Output: 50 Explanatio
12 min read
Extracting PAN Number from GST Number Using Regular Expressions
Given a string str in the form of a GST Number, the task is to extract the PAN Number from the given string. General Format of a GST Number: "22AAAAA0000A1Z5" 22: State CodeAAAAA0000A: Permanent Account Number (PAN)1: Entity Number of the same PANZ: Alphabet Z by default5: Checksum digit Examples: Input: str="23BOSPC9911R2Z5Output: BOSPC9911R Input
4 min read
C++ Program For Partitioning A Linked List Around A Given Value And Keeping The Original Order
Given a linked list and a value x, partition it such that all nodes less than x come first, then all nodes with a value equal to x, and finally nodes with a value greater than or equal to x. The original relative order of the nodes in each of the three partitions should be preserved. The partition must work in place.Examples: Input: 1-&gt;4-&gt;3-
4 min read
Java Program For Partitioning A Linked List Around A Given Value And Keeping The Original Order
Given a linked list and a value x, partition it such that all nodes less than x come first, then all nodes with a value equal to x, and finally nodes with a value greater than or equal to x. The original relative order of the nodes in each of the three partitions should be preserved. The partition must work in place.Examples: Input: 1-&gt;4-&gt;3-
4 min read
Python Program For Partitioning A Linked List Around A Given Value And Keeping The Original Order
Given a linked list and a value x, partition it such that all nodes less than x come first, then all nodes with a value equal to x, and finally nodes with a value greater than or equal to x. The original relative order of the nodes in each of the three partitions should be preserved. The partition must work in place.Examples: Input: 1-&gt;4-&gt;3-
4 min read
Javascript Program For Partitioning A Linked List Around A Given Value And Keeping The Original Order
Given a linked list and a value x, partition it such that all nodes less than x come first, then all nodes with a value equal to x, and finally nodes with a value greater than or equal to x. The original relative order of the nodes in each of the three partitions should be preserved. The partition must work in place.Examples: Input: 1-&gt;4-&gt;3-
4 min read
C++ Program to Find k maximum elements of array in original order
Given an array arr[] and an integer k, we need to print k maximum elements of given array. The elements should printed in the order of the input.Note : k is always less than or equal to n. Examples: Input : arr[] = {10 50 30 60 15} k = 2 Output : 50 60 The top 2 elements are printed as per their appearance in original array. Input : arr[] = {50 8 4
3 min read
Java Program to Find k maximum elements of array in original order
Given an array arr[] and an integer k, we need to print k maximum elements of given array. The elements should printed in the order of the input.Note : k is always less than or equal to n. Examples: Input : arr[] = {10 50 30 60 15} k = 2 Output : 50 60 The top 2 elements are printed as per their appearance in original array. Input : arr[] = {50 8 4
4 min read
Practice Tags :