[2/3] Checking for Leap Year using Conditional Operators
Write a program using conditional operators to determine whether a year
entered through the keyboard is a leap year or not.
#include<stdio.h>
main()
{
int year;
printf("Enter a year:");
scanf("%d", &year);
(year%4==0)?(printf("Leap Year")):(printf("Not a Leap Year"));
}
The file can be found at:
Download File
entered through the keyboard is a leap year or not.
#include<stdio.h>
main()
{
int year;
printf("Enter a year:");
scanf("%d", &year);
(year%4==0)?(printf("Leap Year")):(printf("Not a Leap Year"));
}
The file can be found at:
Download File
Comments
when yr1900 is not leap year.
this prog. will show u that year is leap year
#include
main()
{
int y,leap;
clrscr();
printf("enter any year");
scanf("%d",&y); .
leap=(y%4==0)?( (y%100==0)? ( (y%400==0)? 1 : 0) : 1) : 0;
if(leap ==1)
printf("%d is leap year" ,y);
else
printf("%d is not a leap year" ,y);
getch();
}