May 8, 2012

C Program to find the day of birth.

Write a C Program to find the day of birth when date of birth is given.
In this program we find the day of birth like Monday, Sunday.. when date of birth is given.
Read more about C Programming Language . and read the C Programming Language (2nd Edition). by K and R.


/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                      Happy Coding
***********************************************************/

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>

main()
{
    clrscr();
    int d,m,y,year,month,day,i;
    
    printf("Enter the date :");
    scanf("%d%d%d",&d,&m,&y);
    if( d>31 || m>12 || (y<1900 || y>=2000) )
    {
        if(y>=2000)
        {
            printf("\n\n YOU ARE TOO SMALL To run this program!\n\n");
        }
        printf("INVALID INPUT");
        getch();
        exit(0);
    }
    
    year = y-1900;
    year = year/4;
    year = year+y-1900;
    
    switch(m)
    {
        case 1:
        case 10:
        month = 1;
        break;
        case 2:
        case 3:
        case 11:
        month = 4;
        break;
        case 7:
        case 4:
        month = 0;
        break;
        case 5:
        month = 2;
        break;
        case 6:
        month = 5;
        break;
        case 8:
        month = 3;
        break;
        case 9:
        case 12:
        month = 6;
        break;
    }
    year = year+month;
    year = year+d;
    day  = year%7;
    
    switch(day)
    {
        case 0:
        printf("Day is SATURDAY\n");
        break;
        case 1:
        printf("Day is SUNDAY\n");
        break;
        case 2:
        printf("Day is MONDAY\n");
        break;
        case 3:
        printf("Day is TUESDAY\n");
        break;
        case 4:
        printf("Day is WEDNESDAY\n");
        break;
        case 5:
        printf("Day is THURSDAY\n");
        break;
        case 6:
        printf("Day is FRIDAY\n");
        break;
    }
    
    getch();
    return 0;
}
Read more Similar C Programs
Learn C Programming
Recursion
Number System
You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it


(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!


To browse more C Programs visit this link