C Programming

Solved Example

Practice Questions

Exercise Question

Check a year is leap year or not

Objective:

Program to input a year and check year is a leap year or not.

Program / Solution:

#include<stdio.h>
int main() {
	int y;
	
	printf("Enter the year: ");
	scanf("%d",&y);
	
	if(y % 100 == 0) {
		if(y % 400 == 0) {
			printf("%d is a leap year.",y);
		}else {
			printf("%d is not a leap year.",y);
		}
	}else {
		if(y % 4 == 0) {
			printf("%d is a leap year.",y);
		}else {
			printf("%d is not a leap year.",y);
		}
	}
	
	return 0;	
}
#include<stdio.h>
int main() {
	int y;
	
	printf("Enter the year: ");
	scanf("%d",&y);
	
	if(y % 400 == 0 || y % 100 != 0 && y % 4 ==0) {
		printf("%d is leap year.",y);
	}else {
		printf("%d is not a leap year.",y);
	}
	
	return 0;	
}

Sample Output:

Enter the year: 1996
1996 is a leap year.

Enter the year: 1600
1600 is a leap year.

Enter the year: 1800
1800 is not a leap year.

More Progarms of Decision Making in C

Calculate profit or loss

Check a number is even or odd

Check a number is positive or negative

Find the first day of year

Find the youngest person

Absolute value of a number

Find area of rectangle is greater than perimeter

Check the points are co-linear or not

Check a point is inside,outside or on the circle

Check the axis of a point

Identify a character is alphabet, digit and more

Check the insurance eligibility and calculate premium

Calculate the library penalty charges

Calculate grade of a student