C Programming

Solved Example

Practice Questions

Exercise Question

Program to Calculate gross salary

Objective

Enter the basic salary of a person, if a person 20% DA and 40% HRA pf basic salary, then calculate the Gross salary.

Program Solution

#include<stdio.h>

int main() {
	int basic;
	float da, hra, gross;
	
	printf("Enter the basic salary: ");
	scanf("%d",&basic);
	
	da = basic * 0.2; //20% => 20/100 => 0.2
	hra = basic * 0.4; //40% => 40/100 => 0.4
	
	gross = basic + da + hra;
	
	
	printf("Basic Salary: %d\n",basic);
	printf("DA: %.2f\n",da);
	printf("HRA: %.2f\n",hra);
	printf("------------------------------\n");
	printf("Gross salary = %.2f",gross);
	
	return 0;
}

Output

Enter the basic salary: 8924
Basic Salary: 8924
DA: 1784.80
HRA: 3569.60
------------------------------
Gross salary = 14278.40