Mod Division Question

This is a discussion on Mod Division Question within the C Programming forums, part of the General Programming Boards category; If I had a date entered in the format yyyymmdd how would I use mod division for example on the ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    133

    Mod Division Question

    If I had a date entered in the format yyyymmdd how would I use mod division for example on the years, to cut off the mmdd, and so on. I thought it would be easier to use a string with an array but we haven't covered that in class yet.

    So if anyone knows how would I write the code for 20061010 and print the 2006, 10, and 10, all individually?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,822
    20061010 / 10000 = 2006
    Guess what 20061010 % 10000 is.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    like that ?
    Code:
    int main() {
       long x = 20060106;
       printf("%d, %02d, %02d\n", x/10000, x%10000/100, x%100);
    }
    Kurt

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    Hint: First use % and / separately to read off dd and convert yyyymmdd to yyyymm. Then use the same procedure to read off mm and convert yyyymm to yyyy.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 01:14 PM
  2. Question About Binary Division
    By nirvana21 in forum Tech Board
    Replies: 3
    Last Post: 02-13-2009, 04:20 PM
  3. C++ Simple division question - i hope
    By learning110 in forum C++ Programming
    Replies: 6
    Last Post: 03-20-2003, 06:37 PM
  4. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  5. MOD Question from a newbie
    By BOOGIEMAN in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 12-18-2001, 09:02 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21