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.
C Programming Language Operators and Enums in C Language (Article) Operators and Enums in C Language (Program)
3677
Given Input:
Enter the basic salary of Ramesh: 10000
Expected Output:
Gross salary of Ramesh is: 16000.00
Program:
#include
int main()
{
float basic_salary, dearness_allowance, house_rent_allowance, gross_salary;
printf("Enter the basic salary of Ramesh: ");
scanf("%f", &basic_salary);
dearness_allowance = 0.4 * basic_salary;
house_rent_allowance = 0.2 * basic_salary;
gross_salary = basic_salary + dearness_allowance + house_rent_allowance;
printf("Gross salary of Ramesh is: %.2f", gross_salary);
return 0;
}
Output:
Enter the basic salary of Ramesh: 10000
Gross salary of Ramesh is: 16000.00
Explanation:
This code is written in the C programming language and it calculates the gross salary of an employee named Ramesh.
The first line "#include<stdio.h>" is a preprocessor directive which includes the standard input/output library in the program.
The "int main()" is the main function where the program execution begins.
Inside the main function, four variables are declared: "basic_salary"
, "dearness_allowance"
, "house_rent_allowance"
, and "gross_salary"
which are used to store the values of basic salary, dearness allowance, house rent allowance and gross salary respectively.
The next line, "printf("Enter the basic salary of Ramesh: ");" is used to print a message on the screen asking the user to enter the basic salary of Ramesh.
The next line, "scanf("%f", &basic_salary);" is used to take the input of basic salary from the user.
The next line, "dearness_allowance = 0.4 * basic_salary;" calculates the dearness allowance which is 40% of basic salary.
The next line, "house_rent_allowance = 0.2 * basic_salary;" calculates the house rent allowance which is 20% of basic salary.
The next line, "gross_salary = basic_salary + dearness_allowance + house_rent_allowance;" calculates the gross salary by adding the basic salary, dearness allowance and house rent allowance.
The next line, "printf("Gross salary of Ramesh is: %.2f", gross_salary);" is used to print the gross salary on the screen.
The last line "return 0;" is used to indicate that the main function has been successfully executed.
This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.
Gross salary of Ramesh is: 16000.00
Program:
#include int main() { float basic_salary, dearness_allowance, house_rent_allowance, gross_salary; printf("Enter the basic salary of Ramesh: "); scanf("%f", &basic_salary); dearness_allowance = 0.4 * basic_salary; house_rent_allowance = 0.2 * basic_salary; gross_salary = basic_salary + dearness_allowance + house_rent_allowance; printf("Gross salary of Ramesh is: %.2f", gross_salary); return 0; }
Output:
Enter the basic salary of Ramesh: 10000 Gross salary of Ramesh is: 16000.00
Explanation:
This code is written in the C programming language and it calculates the gross salary of an employee named Ramesh.
The first line "#include<stdio.h>" is a preprocessor directive which includes the standard input/output library in the program.
The "int main()" is the main function where the program execution begins.
Inside the main function, four variables are declared: "basic_salary"
, "dearness_allowance"
, "house_rent_allowance"
, and "gross_salary"
which are used to store the values of basic salary, dearness allowance, house rent allowance and gross salary respectively.
The next line, "printf("Enter the basic salary of Ramesh: ");" is used to print a message on the screen asking the user to enter the basic salary of Ramesh.
The next line, "scanf("%f", &basic_salary);" is used to take the input of basic salary from the user.
The next line, "dearness_allowance = 0.4 * basic_salary;" calculates the dearness allowance which is 40% of basic salary.
The next line, "house_rent_allowance = 0.2 * basic_salary;" calculates the house rent allowance which is 20% of basic salary.
The next line, "gross_salary = basic_salary + dearness_allowance + house_rent_allowance;" calculates the gross salary by adding the basic salary, dearness allowance and house rent allowance.
The next line, "printf("Gross salary of Ramesh is: %.2f", gross_salary);" is used to print the gross salary on the screen.
The last line "return 0;" is used to indicate that the main function has been successfully executed.
This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.