Skip to main content

Today, lets learn how to calculate gross salary in C. I am referring to an awesome book called “Let us C” by “Yashwant Kanetkar” and I will post solutions to the questions asked in exercises. This is the first program of the first chapter: Getting Started. I will be posting more and more programs. If you are unsure about any part and more information, put it down in the comments section below or look it up on Google if you want quick response.  We will try to get back to you as soon as we see the comment.

## Question:

Ramesh’s basic salary is input through the keyboard. His dearness allowance is 40% of basic salary, and house rent allowance is 20% of basic salary. Write a program to calculate his gross salary.

## Solution to calculate gross salary in C:

Here we have to accept Ramesh’s salary through scanf() function of C. We know that his dearness allowance is 40% of basic salary and house rent allowance is 20% of basic salary. Let’s use ‘sal’ as the variable for his basic salary. So, now to calculate his gross salary we will have to deduct his dearness allowance and house rent allowance from his basic salary.

## Program to calculate Ramesh’s gross salary in C:

```#include<stdio.h>
#include<conio.h>

void main(){

float sal,da,hra,gross; //sal=basic salary, da=dearness allowance, hra= house rent allowance, gross= gross salary
printf("Input basic salary - ");
scanf("%f",&sal);
da=0.4*sal; //since it's 40% of basic salary
hra=0.2*sal; //since it's 20% of basic salary
gross=sal-da-hra;
printf("Your gross salary is - %f",gross);
getch();
}```

## Output

Input basic salary – 300000
Your gross salary is – 120000.000000

## Read Also:

Introduction to C Programming

Adding two numbers in C

Subtracting two numbers in C

Multiplying two numbers in C

A highly motivated individual with a hunger to learn and share as much as I can about everything. Masters in Interaction Design with a Bachelors in Computer Science. I have worked with clients across the globe on various design and tech projects. I believe in giving back and that's how ReadMeNow was founded.