The simplest of the decision making in a programming language is if-else.
But before this we need to go inside the operators used for comparison.
#include<stdio.h>
int main(){
int i = 10;
printf("%d %d %d",i>20, i< 20; i ==20);
}
Answer is:
0 1 0
This thing you won't find in most of the books. When a comparison fails then it is replaced by 0 otherwise by 1. In the above example when i>20 proves to be failed, then we have found 0 as the output. Isn't it amazing, how the things are done in a simple manner.
Working example.
#include<stdio.h>
int main(){
int i = 10;
if(i<5)
printf("i is greater than 5\n");
else
printf("i is less than 5\n");
}
Output: i is greater than 5.
But before this we need to go inside the operators used for comparison.
#include<stdio.h>
int main(){
int i = 10;
printf("%d %d %d",i>20, i< 20; i ==20);
}
Answer is:
0 1 0
This thing you won't find in most of the books. When a comparison fails then it is replaced by 0 otherwise by 1. In the above example when i>20 proves to be failed, then we have found 0 as the output. Isn't it amazing, how the things are done in a simple manner.
Working example.
#include<stdio.h>
int main(){
int i = 10;
if(i<5)
printf("i is greater than 5\n");
else
printf("i is less than 5\n");
}
Output: i is greater than 5.