How to write a C Program To Find Week Day Of A Given Date in C Programming Language ?
A real time Program is an Integration of all the constructs what we have learned until now. Hence if your practice on the previous sessions are practically proper then we can attempt any logic which cal make intelligent program. Let us take a test. Let us write a Program to find the WEEK DAY of a Given DATE.
Solution For C Program :
#include<stdio.h>
void main()
{
int d, m, y, n, nleap, nyear, nord, nodd1, nodd2, day, j, sum;
printf("\nEnter Any Date (DD-MM-YYYY) Format Only : ");
scanf("%d-%d-%d", &d, &m, &y);
printf("\n\nDate Entered is : %d - %d - %d", d, m, y);
if(y >= 1600 && y <= 1900)
{
day = 0;
nyear = y - 1600;
}
if(y >= 1901 && y <= 2400)
{
day = 1;
nyear = y - 1901;
}
nleap = nyear / 4;
nord = nyear - nleap;
nodd1 = 2 * nleap + 1 * nord;
day += nodd1 % 7;
sum = 0;
for(j = 1; j < m; j++)
{
switch(j)
{
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
sum += 31;
break;
case 4: case 6: case9: case 11:
sum += 30;
break;
case 2:
if(y % 4 == 0)
sum += 29;
else
sum += 28;
}
}
sum += d;
nodd2 = sum % 7;
day += nodd2;
day %= 7;
switch(day)
{
case 0:
printf("\nDay is Sunday ");
break;
case 1:
printf("\nDay is Monday ");
break;
case 2:
printf("\nDay is Tuesday ");
break;
case 3:
printf("\nDay is Wednesday ");
break;
case 4:
printf("\nDay is Thursday ");
break;
case 5:
printf("\nDay is Friday ");
break;
case 6:
printf("\nDay is Saturday ");
break;
}
}
You may also learn these C Program/Code :
C Program To Swap Two Numbers Without Using Third Variable
Learn More :
Find
- Find out the perfect number using c program
- Find g.c.d of two number using c program.
- Write a c program to find out NCR factor of given number
- How to Write a C program to find maximum between two numbers ?
- Write a C program to find maximum between three numbers ?
- C or C++ program to read marks of 4 subjects and find how many students are pass and fail with division
- C Program turnLEDOn to Drives Forward Until It Finds The Line
- Write overloaded function templates for finding the roots of the linear (a * x + b = 0) and square (a * x2 + b * x + c = 0) uravneniy.Zamechanie: in function to send coefficients of the equations.
- C Program to Find Random Number
- C Program To Find LCM and HCF Of Two Number Using Function - 2
- C Program to find LCM and HCF Of Two Number Using Recursion - 3
- C Program To Find LCM and HCF Of Two Number -1
- C Program To Find Length Of A String Including Blank Spaces, Tabs, And Other Special Characters
- C Program To Find Length Of String And Concatenate Two Strings
- C Program To Find Product Of Two No Using MACRO
- C Program To Find Reverse Of Any Digit Number
- C Program To Find Sum and Difference Of Two Matrices
- C Program To Find The Frequency Of A Number
- C Program To Find The Length, Reverse Of A String And To Check It Is Palindrome or Not
- C Program To Find The Maximum And Minimum Value In An Array
- C Program To Find Transpose Of A Matrix
- C Program To Find Union & Intersection Of Two Array
- C Program Finding the sum of Squares using Recursion
- C Program to Find NCR Of A Given Number Program
- C Program To Find Maximum Of Given Numbers
given
- Give me an integer and I will sum it with the previous natural numbers
- C program calculates a given function in range given by user, stores the data in arrays and displays the answer in a table.
- C Program to Check Given String is Palindrome or Not
- C Program That in a Given Natural Number x Insert Figure c at Position p
- Return the number of tokens given a command
- C Program reads in and spews out the attributes of a given .wav file.
- C Program Recursive function that searches for a given file in a given folder
- C Program to accept m*n matrix from user and display the elements of given matrix using function
- C program to display the transpose of given 3 X 3 matrix
- C Program to convert given decimal number into binary number