[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

Comments

Unknown said…
This comment has been removed by the author.
Unknown said…
this is wrong
when yr1900 is not leap year.
this prog. will show u that year is leap year
Unknown said…
#include
#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();
}
Parag... said…
This comment has been removed by the author.
Parag... said…
This comment has been removed by the author.

Popular posts from this blog

C Program - Calculation of Area and Circumference of a Circle using Pointers

Matchstick Game using C Programming

C Program to Calculate Factorial of a number using Recursion