C Programming
if else StatementIf we want to execute the particular statement on the basis of certain condition, called if else statement.
Syntax
if(condition)
{
//body to execute
}
else
{
//body to execute
}
Example
C program to input a no and check negative no. or positive no./find nature.
void main()
{
int num;
printf("Enter a No.\n");
scanf("%d\n",&num);
if(num>0)
{
printf("Number is Positive");
}
else
{
printf("Number is Negative");
}
getch();
}
Input : -5
Output: Number is Negative
Learn C Programming Free