Gross Salary | CodeChef Solution

Hello coders, today we are going to solve Gross Salary CodeChef Solution whose Problem Code is FLOW011.

Gross Salary

Task

In a company an emplopyee is paid as under: If his basic salary is less than Rs. 1500, then HRA = 10% of base salary and DA = 90% of basic salary.
If his salary is either equal to or above Rs. 1500, then HRA = Rs. 500 and DA = 98% of basic salary. If the Employee’s salary is input, write a program to find his gross salary.

NOTE: Gross Salary = Basic Salary + HRA + DA

Input Format

The first line contains an integer T, total number of testcases. Then follow T lines, each line contains an integer salary.

Output Format

For each test case, output the gross salary of the employee in a new line. Your answer will be considered correct if the absolute error is less than 10-2.

Constraints

  •  T  1000
  •  salary  100000

Example

Sample Input

3
1203
10042
1312

Sample Output

2406.00
20383.16
2624

Solution – Gross Salary | CodeChef Solution

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        float salary = 0, basic, hra, da;
        cin >> basic;
        if (basic < 1500)
        {
            hra = (0.1 * basic);
            da = (0.90 * basic);
        }
        else
        {
            hra = 500;
            da = (0.98 * basic);
        }
        salary += (basic + hra + da);
        cout << fixed << setprecision(2) << salary << "\n";
    }
  return 0;
}

Python

#Solution Provided by CodingBroz
T = int(input())
for i in range(T):
    n = int(input())
    if n < 1500:
        salary = n + (90*n/100) + (10*n/100)
        print(salary)
    else:
        salary = n + (98*n/100) + 500
        print(salary)

Java

import java.util.*;
class CodeChef
{
    public static void main(String args[]){
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        for(int i=0;i<n;i++)
        {
            int a = s.nextInt();
            float sal;
            if(a<1500)
            {
                sal = (float)(a + (0.10*a)+(0.90*a));
            }
            else
            {
                sal = (float) (a+500+(0.98*a));
            }
            System.out.println(sal);
        }
        
    }
}

Disclaimer: The above Problem (Gross Salary) is generated by Hacker Rank but the Solution is Provided by CodingBroz. This tutorial is only for Educational and Learning Purpose.

Leave a Comment

Your email address will not be published. Required fields are marked *