If-else Programs
Code to check number is divisible by 3 and 5
(If number is divisible by both 3&5 then it will print Hi, otherwise it will print bye)
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
printf("Enter any number");
scanf("%d",&a);
if((a%3==0)&&(a%5==0))
{
printf("Hi");
}
else
{
printf("Bye");
}
getch();
}
Output
Code to check leap year
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
printf("Enter year");
scanf("%d",&a);
if(a%4==0)
{
printf("It is a leap year");
}
else
{
printf("It is not a leap year");
}
getch();
}
OUTPUT
Code to check number is even or odd
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
printf("Enter any number");
scanf("%d",&a);
if(a%2==0)
{
printf("It is an even number");
}
else
{
printf("It is an odd number");
}
getch();
}
Comments
Post a Comment