if-else

if-else :-

if the condition is true, then the statement bock within the if will be executed otherwise the else block statement are executed.

 

 

 

Syntax : –

if(condition)

{

statement

}

else

{

statemetn

}

    C program using if-else statement to check whether a no. is even or odd.

 

#include<stdio.h>

#include<conio.h>

void main()

{

int n;

clrscr();

printf("Enter the no.");

scanf("%d",&n);

if(n%2==0)

{

printf("NO. is Even");

}

else

{

printf("No. is Odd");

}

getch();

}

Note :- The No. is Entered by the user is divisible and reminder is zero, then no is even otherwise no odd.

  C Program to check whether the year is leap year or not.

#include<stdio.h>

#include<conio.h>

void main()

{

int n;

clrscr();

printf("\n Enter the Year\n");

Scanf("%d", &n);

if(n%4==0)

{

printf("Year is Leap year");

}

else

{

printf("\nYear is not leap Year");

}

getch();

}
Note :- The no , which is entered by the user, if divisible by  4 and reminder is zero . Then no is even Leap year otherwise year is not Leap year.

 

  C Program to check whether the candidate is eligible for voting or not.

#include<stdio.h>

#include<conio.h>

void main()

{

int age;

clrscr();

pritnf("\n Enter the age.");

Scanf("%d", &age);

if(age>=18)

{

printf("Eligible for Voting");

}

else

{

printf("Not Eligible for Voting");

}

getch();

}
Note :- if condition check that no is greater or equal to 18 , the person is Eligible for voting otherwise not Eligible for Voting.

 

 




Follow Us

Contact Us

tutorialworldin@yahoo.com

Back to Top