i challenge algorithm of days and dates

send me a algorithm to find out the number of days between two given dates

Comments

  • Well I can get you started. I came up with the following formula to calculate the days of a month, taking in regard of course for leap-years
    (This is in Visual Basic, I explain below what each operator returns)

    m: month 1-12
    y: year, four digits

    ((((m mod 8)+int(m/8)) and 1)+29)+(sgn(m and 13)) - (sgn(m and 13) xor 1) * (sgn((y-1900) mod 4))

    mod - Modulus
    int - Rounds down to the closest integer. (i.e INT(2.9)->2)
    sgn - The sign of the number (returns 1, 0 or -1)
    and - Logical And
    xor - Logical Exclusive Or

    /Chris
  • Shit, I just realized that I forgot to take into account that for century-breaks when calculating for leap-years.

    Well, I don't have the time to figure that out right now. Maybe you can correct the formula.

    : Well I can get you started. I came up with the following formula to calculate the days of a month, taking in regard of course for leap-years
    : (This is in Visual Basic, I explain below what each operator returns)
    :
    : m: month 1-12
    : y: year, four digits
    :
    : ((((m mod 8)+int(m/8)) and 1)+29)+(sgn(m and 13)) - (sgn(m and 13) xor 1) * (sgn((y-1900) mod 4))
    :
    : mod - Modulus
    : int - Rounds down to the closest integer. (i.e INT(2.9)->2)
    : sgn - The sign of the number (returns 1, 0 or -1)
    : and - Logical And
    : xor - Logical Exclusive Or
    :
    : /Chris
    :

  • i want the logic in c language so send me aprogram in c language
  • : i want the logic in c language so send me aprogram in c language
    :
    What's the difference which language it is in? Logic is logic, and language is details. Your question, however, sounds very familiar. In fact it sounds exactly like the assignment I recieveda week and a half ago in my C/Unix/Software Tools course in university. If this is where you got it from, I recommend you try to work it out from the logic provided, and not try to scam the solution off someone else.


    There are two methods in software design. One is to make the program so simple, there are obviously no errors. The other is to make it so complicated, there are no obvious errors.

  • : i want the logic in c language so send me aprogram in c language
    :
    What's the difference which language it is in? Logic is logic, and language is details. Your question, however, sounds very familiar. In fact it sounds exactly like the assignment I recieveda week and a half ago in my C/Unix/Software Tools course in university. If this is where you got it from, I recommend you try to work it out from the logic provided, and not try to scam the solution off someone else.


    There are two methods in software design. One is to make the program so simple, there are obviously no errors. The other is to make it so complicated, there are no obvious errors.

  • : i want the logic in c language so send me aprogram in c language
    :

    You seem pretty demanding, no one has to do anything for you, so you would probably get better results asking.
  • : send me a algorithm to find out the number of days between two given dates
    :

    I found a good algorithm in the internet just yesterday. It calculate the julian date from the given month, day and year. Here it is: Just call this function twice, once for each date, then subtract the two numbers that it returns.

    unsigned long jd(int M, int D, int Y)
    // The number of days since noon on January 1, -4712
    // M = month, D = day, and Y = 4-digit year
    // julian date formula from here: http://scienceworld.wolfram.com/astronomy/JulianDate.html
    {

    unsigned long JD = (367 * Y) - (7 * (Y + ((M + 9)/12))/4) - (3 * (((Y + (M - 9)/7)/100) + 1)/4)
    + ((275 * M)/9) + D + 1721028;

    return JD;
    }

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories