How to calculate number of days?

CODE




How to calculate number of days?
Write a program to calculate number of days between given months

int main()
{
    int e,s,c,a[12],sum,i;
    printf("\n enter start month:");
    scanf("%d",&s);
    printf("\n enter end month:");
    scanf("%d",&e);
    c=s;
    for(i=0;i<=e-s;i++)
    {
        if(c==1||c==3||c==5||c==7||c==8||c==10||c==12)
            a[i]=31;
        else if(c==2)
            a[i]=28;
        else
            a[i]=30;
        c++;
    }
    if(c!=s)
    {
        sum=a[0];
        printf("\n %d",a[0]);
        for(i=1;i<=e-s;i++)
        {
            printf(" + %d",a[i]);
            sum+=a[i];
        }
        printf(" = %d",sum);
    }
    else
        printf("\n You have enter wrong information");
}


Output:
enter start month: 4
 enter end month:7

 30 + 31 + 30 + 31 = 122

How to calculate number of days? How to calculate number of days? Reviewed by Unknown on December 16, 2018 Rating: 5

No comments:

If you have any doubt or query ,comment below:

Programming copyright © 2018-19. Powered by Blogger.