Thursday 19 July 2012

Conditional statement014

As per Gregorian calender, 01/01/1900 was Monday. If any year is input through keyboard write a program  to find out what is the day on First January of this year. 



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

void main( )
{
        int           a, b, c, d, e;
        clrscr ( );
        
        printf ("\n Enter year............:"); scanf ("%d",&a);

        b = ( a - 1900);
        c = b/4;
        d = ( b + c ) % 7;
     
        if ( a % 100 == 0 )
        {      
                   if ( a % 400 == 0 )
                              e = d -1;
                   else  
                              e = d;
        }                                    
        else                          
        {                              
                   if ( a % 4 == 0 )
                              e = d -1;
                   else                                          
                              e = d;
        }                                          
        if ( e == 0 )
                    printf ("\n MONDAY");
        if ( e == 1 )
                    printf ("\n TUESDAY");
        if ( e == 2 )
                    printf ("\n WEDNESDAY");
        if ( e == 3 )
                    printf ("\n THURSDAY");
        if ( e == 4 )
                    printf ("\n FRIDAY");
        if ( e == 5 )
                    printf ("\n SATURDAY");
        if ( e == 6 )
                    printf ("\n SUNDAY");
        if ( e == -1 )
                    printf ("\n MONDAY");
        getch ( );
}

To contact us

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...