Program to find the day of the given date
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int date, mon, year, i, r, s = 0;
char week[7][10];
clrscr();
strcpy(week[0], "Sunday");
strcpy(week[1], "Monday");
strcpy(week[2], "Tuesday");
strcpy(week[3], "Wednesday");
strcpy(week[4], "Thursday");
strcpy(week[5], "Friday");
strcpy(week[6], "Saturday");
printf("Enter a valid date (dd/mm/yyyy) : ");
scanf("%d / %d / %d", &date, &mon, &year);
if( (year / 4 == 0) && (year % 400 == 0) && (year % 100 != 0))
month[1] = 29;
for(i = 0 ; i < mon - 1 ; i++)
s = s + month[i];
s = s + (date + year + (year / 4) - 2);
s = s % 7;
printf("\nThe day is : %s", week[s]);
getch();
}
Output:
Enter a valid date (dd/mm/yyyy) : 02/11/1977
The day is : Wednesday
-
UpdatedDec 30, 2019
-
Views23,322
You May Like
Program to maintain employee details using structures
Program to maintain student details using structures
Check whether the person is eligible to vote or not
Print the numbers that are divisible by a given no.
Program to generate magic square
To sort the given numbers in ascending & descending order