Control
Statements
v if Statement:
The if statement is decision making statement.
Syntax:
If(test Condition)
{
Statement 1;
Statement 2;
.
.
.
.
Statement n;
}
Statement X;
Statement Y;
Statement Z;
§ if is a keyword, which is use to
check condition/expression.
§ When the if statement condition is True,
all statements in if blocks is executing then execute statement X, statement Y
and statement Z.
§ When the if statement condition is
False, all statements in if blocks is not executing. Only statement X,
statement Y and statement Z are executing.
§ The condition is always enclosed
within the pair of round braces i.e. parenthesis ().
Program:
While purchasing of cloths, discount
of 10% is offered if the total bill is more than 1000. If total bill is input
through the keyboard, write a program to calculate total bill.
/*
Prog no-3 Demo of if statement */
#include
<stdio.h>
#include
<conio.h>
void
main()
{
int bill,dis=0;
clrscr();
printf("\n\nEnter Total bill of cloths : " );
scanf("%d",&bill);
if(bill>1000)
{
dis=10;
dis=bill*dis/100;
bill=bill-dis;
}
printf("\nDiscount is = %d",dis);
printf ("\nFinal bill of clothes =
%d", bill);
getch();
}
Flowchart:
0 Comments