Thread: one problem in C

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    6

    one problem in C

    Determine the largest number that can be formed with all the figures given number.
    In my opinion you take the number, it becomes a vector of numbers, sort the array and turn back vector of digits in number.
    I think that is a way. OK, but how to do this (it becomes a vector of numbers) ?

  2. #2
    Registered User
    Join Date
    Oct 2011
    Posts
    6

    one problem in C

    completion

    for instance : the number is 62476
    the highest number is 76642

  3. #3
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Is this related to one problem in C? Keep related posts in the same thread.

  4. #4
    Registered User TheBigH's Avatar
    Join Date
    May 2010
    Location
    Melbourne, Australia
    Posts
    426
    Read our homework policy.

    And why would you start two threads for this?
    Code:
    while(!asleep) {
       sheep++;
    }

  5. #5
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Yes, that is one way to do it. Look into the % (modulus) operator for separating the digits. Keep them in an array of ints.

    If you want more help than that, try working out a solution by hand (including testing some examples), then code it up. Post your attempt in code tags and ask specific questions.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Threads merged.
    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.

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    While the number is greater than zero, use % modulus 10 to determine the right most digit. Save that to your int array[i]. Divide the number by 10, and increment i.

    To print out your number, you'll need to go backward, digit by digit, from numberArray[i] to numberArray[0]. While(i) is a simple way to start that second while loop.

  8. #8
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Quote Originally Posted by Adak View Post
    While the number is greater than zero, use % modulus 10 to determine the right most digit. Save that to your int array[i]. Divide the number by 10, and increment i.

    To print out your number, you'll need to go backward, digit by digit, from numberArray[i] to numberArray[0]. While(i) is a simple way to start that second while loop.
    The first half of this applies to the OP's problem, but the second half does not. The problem isn't to reverse the number, it's to rearrange the digits to make the largest possible number.

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by anduril462 View Post
    The first half of this applies to the OP's problem, but the second half does not. The problem isn't to reverse the number, it's to rearrange the digits to make the largest possible number.
    I'm using the "Divide and Conquer" approach. One step at a time. The fact that the digits are reversed doesn't affect the problem. The digits can now be easily sorted, so their order will change, anyway.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 10-16-2008, 07:30 PM
  2. sturct/pointer problem, and fscanf problem
    By hiphop4reel in forum C Programming
    Replies: 6
    Last Post: 07-28-2008, 09:40 AM
  3. Replies: 27
    Last Post: 10-11-2006, 04:27 AM
  4. Visual Studio Linker problem or my problem?
    By OOPboredom in forum C Programming
    Replies: 2
    Last Post: 04-13-2004, 12:32 AM
  5. syntax linked list problem & struct problem
    By beely in forum C Programming
    Replies: 5
    Last Post: 11-11-2002, 09:14 AM

Tags for this Thread