92 : Check if entered year is a leap year using ternary operator

Check out the complete list of c-programs : C Program List    












/*
 ============================================================================
 Name        : C-Programming
 Author      : Code2care
 Version     : 1.0
 Copyright   : Code2care.org
 Description : 92 : Check if entered year is a leap year using ternary operator
 ============================================================================
 */

#include 
#include 

int main(void) {

	int year, leap_flag;

	printf(
			"C Program to check entered year is a leap year or not using ternary operator :");
	printf("\nEnter Year : ");
	scanf("%d", &year);

	leap_flag = (year % 400 == 0) ? :
				(year % 100 != 0) ? (year % 4 == 0) ? 1 : 0 : 0;

	if (leap_flag == 1) {

		printf("\n %d is a leap year!", year);
	} else {
		printf("\n %d is not a leap year!", year);
	}

	return 0;
}









The best way to learn C programming is to practice more and more of programs . Code2care C Programming tutorials provide 1000+ programs in C that you can study and become an expert in the language. Programs are divided into categories depending upon type and complexity.

BSc. IT, BSc. Computer Science, BSc. IT, MSc. IT, MSc. Computer Science, MCA, BTech IT & BTech Engineers may find these programs very useful.