The C program given below is a program that will ask you a year showing a message Enter a year: . When you will input a year using the keyboard, then the program will check whether it is a leap year or not. Most of the description of the codes are given after the statement in different color. Ignore the description when you will type the program in a compiler like Turbo C, CodeBlocks etc.
#include<stdio.h>
#include<conio.h>
main()
{
int year; /*Declaring an integer type variable called year*/
printf("Enter a year: "); /*Showing a message*/
scanf("%d",&year); /*Getting value from keyboard*/
if(year%4==0) /*Checking if the data is divisible by 4*/
{
printf("The year is leap year"); /*If the year is divisible by 4, then showing a message*/
}
else
{
if(year%100==0) /*Again checking, if the data is divisible by 100*/
{
if(year%400==0) /*Again checking, if the data is divisible by 400*/
{
printf("the year is leap year"); /*If the year is divisible by 100 and 400, then showing a message*/
}
}
else
printf("the year is not leap year"); /*If all the conditions are wrong, then showing a message*/
}
getch();
}
No comments:
Post a Comment