C Programming

Solved Example

Practice Questions

Exercise Question

Find the first day of year

Objective:

As per the gregorian calendar, It is Monday on the date 1/1/1900. Input any year and find what will be the first day of that year.

Program / Solution:

#include<stdio.h>
int main() {
	int y,skipdays,leapdays,totalskipdays;
	printf("Enter any year: ");
	scanf("%d",&y);
	
	skipdays = (y - 1) * 365;
	leapdays = (y - 1) / 4 - (y - 1) / 100 + (y - 1) / 400;
	
	totalskipdays = skipdays + leapdays;
	
	switch(totalskipdays % 7) {
		case 0:
			printf("Monday");
			break;
		case 1:
			printf("Tuesday");
			break;
		case 2:
			printf("Wednesday");
			break;
		case 3:
			printf("Thrusday");
			break;
		case 4:
			printf("Friday");
			break;
		case 5:
			printf("Saturday");
			break;
		case 6:
			printf("Sunday");
			break;
	}
	
	return 0;
}

Sample Output:

Enter any year: 2004
Thrusday

Enter any year: 2020
Wednesday

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

Check a year is leap year or not

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