Syntax is as follow:
if (condition)
{
Statements to be executed;
}
If the condition is true then only the statement will be executed.
Following expressions are used in the condition:
x = = y if x is equal to y
x ! = y if x is not equal to y
x > y if x is greater than y
x >= y if x is greater than or equal to y
x < y if x is less than y
x <= y if x is less than or equal to y
Note that, here = = sign is used for the comparison not = sign.
#include <stdio.h>
#include <conio.h>
void main()
{
int i;
printf(“Enter an integer: ”);
scanf(“%d”,&i);
if (i<=0)
{
printf(“\nYou have entered a non-positive integer”);
}
return;
}
In C any non-zero quantity is considered as true. Now look at following examples:
if (10)
{
printf(“This statement will be executed”);
}
In the above example, the statement within () is 10, which is true since it is non zero, hence the statement will be executed.
Urgenthomework helped me with finance homework problems and taught math portion of my course as well. Initially, I used a tutor that taught me math course I felt that as if I was not getting the help I needed. With the help of Urgenthomework, I got precisely where I was weak:
Read More
Follow Us