The if-else Statement
The main aim of if-else statement is to execute one group of statement if condition is true and other group statement if the condition is false.SYNTAX
if(test condition)
{
True statement portion
}
else
{
False statement portion
}
Next statement
Here if the test condition is true then the true portion will be executed otherwise false statement will be executed .
Example
/*calculation of net salary*/
#include<stdio.h>
#include<conio.h>
Void main()
{
int basic;
float net,da,hra;
Printf("enter basic pay\t");
scanf("%d",&basic);
if(basic<10000)
{
da=basic*0.50;
har=basic*0.20;
net=basic+da+hra;
}
else
{
da=basic*0.14;
har=basic*0.10;
net=basic+da+har;
}
printf("net salary=%f",net);
getch();
}
Output
enter basic 8475
net salary=14407.50000000
enter basic 10325
net salary=15487.50000000


0 Comments