This program determines whether the given year is a leap year or not.This problem also illustrates the use of the control statemen if-else!!
LOGIC:
If the year is divisible by 4 it is a leap year.
If the year is divisible by 100 it is not a leap year.
If the year is divisible by 400 it is a leap year.
PROGRAM:
LOGIC:
If the year is divisible by 4 it is a leap year.
If the year is divisible by 100 it is not a leap year.
If the year is divisible by 400 it is a leap year.
PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
#include<conio.h>
void main()
{
int year;
clrscr();
printf("Enter the year:");
scanf("%d",&year);
int year;
clrscr();
printf("Enter the year:");
scanf("%d",&year);
if(year%100==0)
{
if(year%400==0)
{
printf("%d Is a leap year",year);
}
else
{
printf("%d Is a non-leap year",year);
}
}
else
{
if(year%4==0)
{
printf("%d: It is a leap year",year);
}
else
{
printf("%d: It is not a leap year",year);
}
}
printf("\n~!Anyway have a nice year!~");
getch();
}{
if(year%400==0)
{
printf("%d Is a leap year",year);
}
else
{
printf("%d Is a non-leap year",year);
}
}
else
{
if(year%4==0)
{
printf("%d: It is a leap year",year);
}
else
{
printf("%d: It is not a leap year",year);
}
}
printf("\n~!Anyway have a nice year!~");
getch();
No comments:
Post a Comment