Thursday, April 09, 2009

Exercise Solving 1

Exercise 1:
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 C program to calculate his gross salary.


Solution:

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

void main()
{
float basic, da, hra, gross;                                     /* Declaration of the variables used in the program */
printf(“Please enter your Basic Salary = Rs ”);       /* Printing of the user friendly statement */
scanf(“%f”, &basic);                                               /* Inputting of the basic salary from the user */
da=40*basic/100;                                                     /* Calculation of DA */
hra=20*basic/100;                                                    /* Calculation of HRA */
gross=basic+da+hra;                                                 /* Calculation of Gross Salary */ 
printf(“\nTherefore the Gross Salary = Rs %.2f”, gross);       /* Displaying the result */
getch();                                                                     /* Pause the output screen */
}
This is a very simple program, where the basic salary is to inputted from the user and then calculating the DA & HRA and adding them all to get the gross salary. The result is then displayed to the user.
The output of the program is as follows:
Please enter your Basic Salary = Rs 10000
Therefore the Gross Salary = Rs 16000.00

3 comments:

  1. /*guys what about this*/

    #include

    void main()

    {

    float basicsalary,dearnessalowance,houserentalowance,grosssalary;

    printf ("\nto calculate the gross_sallary");

    scanf("%f\n",&basicsalary);

    dearnessalowance=basicsalary*40/100;

    printf("%fdearnessalowance\n",dearnessalowance);

    houserentalowance=basicsalary*20/100;

    printf("%f",houserentalowance);

    grosssalary=basicsalary+dearnessalowance+houserentalowance;

    printf("\n%fgrosssalary",grosssalary);

    }

    ReplyDelete

Please give your valuable comments or queries if you fell its helpful or if you like the contents of the site. Thanks...