C-Program : WAP to Print Present Day of the Year - Cipheronics - Codes n' Electronics.

Hot

Post Top Ad

Responsive Ads Here

Saturday, 22 July 2017

C-Program : WAP to Print Present Day of the Year

This is a C-Program to print the present day by taking the 1st day of the Year.

#include <stdio.h>

int main ()
{
    //declaring the variables.
    int day , y , val, yes=y;

    //runs the program over again
    while ( 1 )
    {
        printf("Select the First Day of the Year : ");
        printf ("1. Sunday.\n2. Monday.\n3. Tuesday.\n4. Wednesday\n5. Thursday\n6. Friday\n7. Saturday\n");

        scanf("%d", &day);

        printf("Enter the number to check on which the day it falls on : ");
        scanf ("%d", &y );

        //this will check the condition

        val = ( y + ( day -1 )) % 7  ;
       
        switch (val)
        {
            case 1:
                printf("%d day is Sunday\n", y );
                break;

            case 2:
                printf("%d day is Monday\n", y );
                break;

            case 3:
                printf("%d day is Tuesday\n", y );
                break;

            case 4:
                printf("%d day is Wednesday\n", y );
                break;

            case 5:
                printf("%d day is Thursday\n", y );
                break;

            case 6:
                printf("%d day is Friday\n", y );
                break;

            case 0:
                printf("%d day is Saturday\n", y );
                break;
        }

        // This is for running the loop again.

        printf("To continue ['Y'/'n'] : ");
        yes=getchar();
        getchar();
        if (!( yes == 'y' || yes == 'Y'))
        {
            break;
        }
    }
    return 0;
}


Have a problem.? Then Discuss it in Forums here

No comments:

Post a Comment

Post Top Ad

Responsive Ads Here