|
|
if else in C programWe can use decision making statement if else inside our c code. For this we will start with some simple if else statement and write complex programs in our c language.
If( test expression )
{
Statement block if TRUE
}
Similarly we can add else part to our if condition so if the test expression fails then this part gets executed. We will start with an example. We will ask users to enter one digit , then we will check if it is greater than 10 or not. But to display a message if the condition checking fails we have to use one else block also. Here is the code.
#include <stdio.h>
int main(void){
int num1;
printf("Enter the number ");
scanf("%d",&num1); // Enter numbers
if(num1 <= 10)
{
printf(" Your number is less than or equal to ten");
}
else
{
printf(" Your number is more than ten"); // printng outputs
}
return 0;
}
| |
| |
|
|
|
|
|