Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

years problem

0 votes
asked Oct 20, 2018 by Στάθης Χόρτης (120 points)

 To write a program that accepts one year and decides whether it is a loser or not. The volume is one year if it divides exactly with 4. The year's, however, divided by 100 are not loose apart and cross with 100 are not disjoint unless divided by the 400To write a program that accepts one year and decides whether it is a loser or not. The volume is one year if it divides exactly with 4. The year's, however, divided by 100 are not loose apart and cross with 100 are not disjoint unless divided by the 400.

i try this but is false any help?

#include <stdio.h>
#include <stdlib.h>
int main()
{
    long d1,d2,m1,m2,y1,y2,days1,days2,diff,d,m,y;

    printf ("Give first date (dd mm yyyy): ");
    scanf("%ld %ld %ld",&d1,&m1,&y1);
    printf ("Give second date (dd mm yyyy): ");
    scanf("%ld %ld %ld",&d2,&m2,&y2);

    days1=d1+(m1-1)*30+(y1-1)*360; //Convert date 1 to days
    days2=d2+(m2-1)*30+(y2-1)*360; //Convert date 2 to days
    diff=days1>days2?days1-days2:days2-days1; //Absolute value of the difference
    printf ("The space between the give n dates is %ld days!\n",diff);

    y = diff/360;
    diff=diff%360;
    m=diff/30;
    d=diff%30;
    //Convert days back to years,months,days
    printf ("The space between the given dates is %ld years, %ld months and %ld days!\n",y,m,d);

    return 0;
}

1 Answer

0 votes
answered Oct 25, 2018 by Davi
#include <stdio.h>
#include <stdlib.h>
int main ()
{
    long d1, d2, m1, m2, y1, y2, dias1, dias2, diff, d, m, y;

    printf ("Dar a primeira data (dd mm aaaa):");
    scanf ("%ld %ld %ld", &d1, &m1, &y1);
    printf ("Dar segunda data (dd mm aaaa):");
    scanf ("%ld %ld %ld", &d2, &m2, &y2);

    dias1 = d1 + (m1-1)* 30 + (y1-1) * 360; // Converter data 1 para dias
    dias2 = d2 + (m2-1)* 30 + (y2-1) * 360; // Converter data 2 para dias
    diff = dias1>dias2 ? dias1-dias2: dias2-dias1; // Valor absoluto da diferença
    printf ("O espaço entre as datas dadas é% ld dias! \ n", diff);

    y = diff / 360;
    diff = diff% 360;
    m = diff / 30;
    d = diff% 30;
    // Converter dias de volta para anos, meses, dias
    printf ("O espaço entre as datas dadas é% ld anos,% ld meses e% ld dias! \ n", y, m, d);

    return 0;
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...