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.
Download the source code:
Download ProgramProgram 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