C PROGRAM TO PRINT THE REMAINING DAYS AND COMPLETED DAYS FROM A GIVEN DATE

 Consider the following I/O samples.

 

SAMPLE INPUT:  23 08 2000

SAMPLE OUTPUT:  Remaining Days : 130

                         Completed Days : 236  


            
C PROGRAM:  

#include <stdio.h>
int main()
{
    int d,m,y,sum=0;
    scanf("%d %d %d",&d,&m,&y);
    if(d>31 || m>12)
        printf("Invalid");
    else
    {
        switch(m)
        {
            case 1: sum+=31;
            case 2: 
                if((y%4==0 && y%100!=0) || y%400==0)
                    sum+=29;
                else
                    sum+=28;
            case 3: sum+=31;
            case 4: sum+=30;
            case 5: sum+=31;
            case 6: sum+=30;
            case 7: sum+=31;
            case 8: sum+=31;
            case 9: sum+=30;
            case 10: sum+=31;
            case 11: sum+=30;
            case 12: sum+=31;
        }
    sum=sum-d;
    printf("Remaining Days : %d\n",sum);
    if((y%4==0 && y%100!=0) || y%400==0)
        printf("Completed Days : %d",366-sum);
    else
        printf("Completed Days : %d",365-sum);
    }
    return 0;

}


OUTPUT:

 



 
The given source code in C program is short and simple to understand. The source code is well tested in DEV-C++ and is completely error free. 

If you have any feedback about this article and want to improve this, please comment in the comment section.

 

Comments

Popular posts from this blog

C PROGRAM TO CHECK BALANCED PARENTHESIS - ( { [

C PROGRAM FOR Mth LARGEST AND Mth SMALLEST ELEMENT IN AN ARRAY

TRIANGULAR NUMBER OR NOT