Program to calculate Gross Salary

Description

Gross salary is the sum of basic salary, da and hra.

C/C++

/* C Program to calculate Gross Salary */
//Save it as GrossSalary.c

#include<stdio.h>
int main(){

    float basicSalary, da, hra, grossSalary;

    printf("Enter the basic salary : ");
    scanf("%f",&basicSalary);

    printf("Enter the da in percentage : ");
    scanf("%f",&da);

    printf("Enter the hra in percentage : ");
    scanf("%f",&hra);

    //Calculate da value
    float daVal = (basicSalary * da)/100;

    //Calculate hra value
    float hraVal = (basicSalary * hra)/100;

    //Calculate gross salary value
    grossSalary = basicSalary + daVal + hraVal;

    printf("The Gross salary = %.3f",grossSalary);

    return 0;
}
Input:
Enter the basic salary : 1000
Enter the da in percentage : 10
Enter the hra in percentage : 12

Output:
The Gross salary = 1220.0

Java

/* Java Program to calculate Gross Salary */
//Save it as GrossSalary.java

import java.io.*;
import java.util.Scanner;

public class GrossSalary {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        
        float basicSalary, da, hra, grossSalary;

        System.out.println("Enter the basic salary : ");
        basicSalary = scanner.nextFloat();

        System.out.println("Enter the da in percentage : ");
        da = scanner.nextFloat();

        System.out.println("Enter the hra in percentage : ");
        hra = scanner.nextFloat();
        
        //Calculate da value
        float daVal = (basicSalary * da)/100;

        //Calculate hra value
        float hraVal = (basicSalary * hra)/100;

        //Calculate gross salary value
        grossSalary = basicSalary + daVal + hraVal;

        System.out.println("The Gross salary = "+grossSalary);
    }
}
Input:
Enter the basic salary : 
1000
Enter the da in percentage : 
10
Enter the hra in percentage : 
12

Output:
The Gross salary = 1220.0

Related Programs

1) Program to find simple interest
2) Program to calculate percentage mark of student
3) Program to calculate Grade of Student
4) Program to display multiplication table of a number
5) Program to convert Octal to Decimal
6) Program to find HCF using Recursion
7) Simple Calculator Using If Else
8) Program to calculate Volume and Surface Area of Sphere
9) Program to find greatest of 3 numbers
10) Check whether a given number is a perfect number or not
Share Me

Leave a Reply