🔥🔥Chapter-3 🔥🔥 Conditional Instruction🔥🔥(Decision Making)
Decision making Instruction in C language are of two types:-
1. If-else Statement
2. Switch Statement
1. If-else Statement
//Here we are checking thar the number is Odd or even by C program
#include <stdio.h>
int main()
{
int a;
printf("Enter any Number to chack the it is odd or even=");
scanf("%d", &a);
if (a % 2 == 0)
{
printf("The Number is ODD");
}
else
{
printf("The Number is EVEN");
}
return 0;
}
(i) Relational Operator in C language by if-else
//Here we are leasrning how to use the relational Operator
// Relational Operator such as :- [==, <=, >=, !=]
#include <stdio.h>
int main()
{
int age;
printf("Enter the AGE to check you can drive or not");
scanf("%d", &age);
if (age <= 90) //Here is <= it is the relational Operator
{
printf("You can drive your age is Under than 90\n");
}
else
{
printf("You can not drive");
}
return 0;
}
(ii) Logical Operator in C language by if-else
#include <stdio.h>
int main()
{
int age;
int vippass = 1;
printf("Enter the age to check you can rive or not= ");
scanf("%d", &age);
if ((age <= 18 || age >= 90) && !(vippass == 1))
{
printf("You are not eligible to drive");
}
else
{
printf("You are eligible to drive");
}
return 0;
}
🔥🔥 The most important that in logical operator && and in this the statement is true when both or all are true if there is any condition which is not true then it is not true it become false 🔥🔥 while in the || or operator it need only one condition to true and it will true
For and 0 and 0 is false 🔥
0 and 1 is false 🔥
1 and 1 is true 🔥
Comments
Post a Comment