Control
Statements
v if-else statement:
When to choose one alternative out of two if-else statement is used.
Syntax:
If(test Condition)
{
Statement 1;
Statement 2;
.
.
.
.
Statement n;
}
else(test Condition)
{
Statement 1;
Statement 2;
.
.
.
.
Statement n;
}
Statement X;
§ If-else is a keyword, which is use to
check condition/expression.
§ It is used to choose one alternative
out of two.
§ When the if statement condition is True,
all statements in if blocks is executing otherwise else block all statements
are executed.
§ then execute statement X.
§ The condition is always enclosed
within the pair of round braces i.e. parenthesis ().
Program:
Write a program to check greater/maximum
number amongst 2 numbers.
/*
Prog no-9 Program to find greater/maximum number amongst 2 numbers */
#include
<stdio.h>
#include
<conio.h>
void
main()
{
int a,b;
clrscr();
printf("\n\nEnter two numbers : " );
scanf("%d %d",&a,&b);
if(a>b)
{
printf("\nGreater/Maximum
number = %d",a);
}
else
{
printf("\nGreater/Maximum
number = %d",b);
}
getch();
}
Output
0 Comments