Example:
Given the basic pay of a employee, write a program to calculate the HRA according to the following conditions.
Solution
•Algorithm:
1. Input basic pay, bp
2. IF (bp <= 2000) THEN HRA = 200
3. IF ( bp > 2000 and bp <= 4000 ) THEN HRA = 350
3. IF (bp > 4000) THEN HRA 500
5. Output HRA
6. STOP
•Flowchart:
•Program in C :
#include <stdio.h>
main()
{
int bp,hra:
printf ("Enter the basic pay:")
scanf("d",&bp);
if (bp < 2000) hra=200;
if(bp 2000 && bp <= 4000) hra = 350;
if(bp 4000) hra = 500;
printf("Hra is: %d",hra);
}
Run:
Enter the basic pay : 2400
Hra is : 350
•If.......else STATEMENT
The general form of this statement is
if(condition)
{
statement-1;
}
else
{
statement-2;
}
If the given condition is true then staternent-1 is executed otherwise statement-2 will be executed Flow chart.
0 Comments