Monday, July 10, 2006

[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

6 comments:

Tashika said...

thanks

Avijit Sadhukhan said...
This comment has been removed by the author.
Avijit Sadhukhan said...

this is wrong
when yr1900 is not leap year.
this prog. will show u that year is leap year

Avijit Sadhukhan 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.