The condition is any expression that returns a boolean value. An if statement executes code conditionally depending on the result of the condition in parentheses. When condition in parentheses is true it will enter to the block of if statement which is defined by curly braces like open braces and close braces. Opening bracket till the closing bracket is the scope of the if statement. The else block is optional and can be omitted.It runs if the if statement is false and does not run if the if statement is true because in that case if statement executes.
Syntax:
if( condition )
{
// body of the statements will execute if the condition is true ;
}
else
{
// body of the statements will executed if the condition is false;
}
The code is a C program that demonstrates the use of the if-else statement in C. Here is an explanation of each line of the code:
The above program prompts the user to enter their name and age. Then it checks if the entered age is greater than or equal to 18. If it is true, it prints a message stating that the user is eligible to vote. If it is false, it prints a message stating that the user is not eligible to vote.
//if else statement #include<stdio.h> int main() { char name[10]; int age; printf("\nEnter Your Name : "); scanf("%s",name); printf("\nEnter The Age : "); scanf("%d",&age); if(age>=18) { printf("\n %s age is %d Eligible For Vote",name,age); } else { printf("\n %s age is %d Not Eligible For Vote",name,age); } return 0; }To download raw file Click Here
Enter Your Name : Ram Enter The Age : 17 Ram age is 17 Not Eligible For Vote
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions