Leap Year Program In C using if-else
// Leap year program in c using if-else
#include<stdio.h> int main() { // Declaring variable for y=year int y; // Inputing year printf("Enter year to check leap year or not: "); scanf("%d",&y); // Determining and displaying whether leap year or not if(y%4==0) { if(y%100==0 && y%400!=0) printf("Century year, But not a leap year"); else printf("Leap year"); } else printf("Not a Leap Year"); return 0; }
Leap Year Program In C Using Ternary
// Leap year program in c using ternary
#include<stdio.h>int main() { // Declaring variable "y" to input year and "leap" to determine leap year int y,leap; // Inputting year printf("Enter any year : "); scanf("%d",&y); // Checking if leaf year or not leap=(y%400==0)?:(y%100!=0)?(y%4==0)?1:0:0; if(leap==1) printf("The given year is leap year"); else printf("The given year is not leap year"); return 0; }