Thursday, 1 February 2018

Example if and if-else Conditions in C Language

1.Two integer numbers are input through the keybord. Write a program find out the greater no.

#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
int x,y;
printf(“enter the no”);
scanf(“%d%d”,&x,&y);
if(x>y)
printf(“x is greater”);
if(y>x)
printf(“y is greater”);
getch( );
}

Output:

enter the no 20
16
x is greater
enter the no 6
8
y is greater


2.Write a program find out the no is even or odd.

#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
int a;
printf(“enter the no”);
scanf(“%d”,&a);
if(a%2==0)
printf(“even no”);
if(a%2!=0)
printf(“odd no”);
getch( );
}


Output:

enter the no 22
even no

enter the no 11
odd no

3.Write a program to find out year is leap year or not.

#include<stdio.h>
int main()
{
    int year;
    printf("enter the year=");
    scanf("%d",&year);
    if(year%400==0)
    {
        printf("year is leap year");
    }
    else if((year%100!=0)&&(year%4==0))
        {
        printf("year is leap year");
        }
        else
        {
        printf("year is not leap year");
        }
}   

Output:

enter the year= 2000
year is leap year

enter the year= 1999
year is not leap year


4.Three integer numbers are input through the keybord. Write a program find out the greater no.

#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
int x,y,z;
printf(“enter the no”);
scanf(“%d%d%d”,&x,&y,&z);
if(x>y&&x>z)
printf(“x is greater”);
if(y>z&&y>x)
printf(“y is greater”);
else
printf(“z is greater”);
getch( );
}

Output:

enter the no 6 5 4
x is greater
enter the no 7 10 6
y is greater
enter the no 100 200 201
z is greater


Share this

0 Comment to "Example if and if-else Conditions in C Language"

Post a Comment