Thread: Mod Division Question

  1. #1
    Registered User
    Join Date
    Apr 2007

    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
    The edge of the known universe
    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.

  3. #3
    Registered User
    Join Date
    Aug 2005
    like that ?
    int main() {
       long x = 20060106;
       printf("%d, %02d, %02d\n", x/10000, x%10000/100, x%100);

  4. #4
    Registered User
    Join Date
    Sep 2006
    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, 12: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
    Replies: 2
    Last Post: 12-18-2001, 09:02 AM