Leap year program using Ternary operator

This “Leap year program using Ternary Operator” post providing implementation of program to check given input number is Leap year or not using Ternary operator or Conditional operator in C language.


#include<stdio.h>
void main()
{
int y ;
printf(“Enter year : “);
scanf(“%d”, &y);
y%400==0 && y%100 ==0 || y%4==0 && y%100 != 0 ? printf(“Leap”) : printf(“Not leap”);
}


#include<stdio.h>
void main()
{
int y ;
printf(“Enter year : “);
scanf(“%d”, &y);
y%400==0 ? printf(“Leap”) : y%4==0 && y%100!=0 ? printf(“Leap”) : printf(“Not leap”);
}

Share this