In this post, I am going to write a C program with nested if statements to find the Leap year.
This example C program is very much useful for school students and for the beginners.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
// include the header files #include <stdio.h> #include <stdlib.h> void main() { int x; printf("Enter a year:"); scanf("%d", & x); // nested if statements to check Leap year if (x % 4 == 0) { if (x % 100 == 0) { if (x % 400 == 0) { printf("%d is a leap year", x); exit(0); } else { printf("%d is not a leap year", x); exit(0); } } else { printf("%d is a leap year", x); } } else { printf("%d is not a leap year", x); } } |
I believe this post would have helped you to understand how to write a nested If statement in C language and also how to find leap year.