Monday, 19 September 2011

control statement in C

Example of if statement..
Que: Program in, input the salary of en emplyee and if salary is greater than Rs. 5000 then calculate total salary by bonus 5 %.

#include<stdio.h>
#include<conio.h>
void main()
{
float sal,bonus=0;
clrscr();
printf("Enter the salary of the emplyee: ");
scanf("%f",&sal);
if(sal>5000)
bonus=sal*5/100;
sal=sal+bonus;
printf("Total salary is : %f",sal);
getch();
}

Explanation:
if(condition)
{
true body;
operations;
..........;
.........;
.........;
}
else
{
false body;
operations;
............;
............;
............;
}
(if true body is of single line statement then there is no need of braces({}).)
a statement terminated by semicolon(;)

No comments:

Post a Comment