if….else
statement
The if else is
actually just on extension of the general format of if statement. If the result of the condition is
true, then program statement 1 is executed,
otherwise program statement 2 will be executed.
If any case either program statement 1 is executed or
program statement 2 is executed but
not both.
if(Test
Condition)
{
Statement-1;
}
else
{
Statement-2;
}
Next-statement;
Sample Program to print whether
given number is odd or even.
#include<stdio.h>
#include<conio.h>
void main ()
{
int n;
printf(“Enter
n: “);
scanf(“%d”,&n);
if(n%2==0)
{
printf(“EVEN”);
}
else
{
printf(“ODD”);
}
}
Output:-
Enter n: 43
ODD
No comments:
Post a Comment