Thread: printing number from array question..

  1. #31
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,334
    Then you broke laserlight's code. If you run it, exactly as written, you will actually get 1000.

  2. #32
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,401
    Quote Originally Posted by transgalactic2
    i get 000000000000000000000000000000000000....00001000
    when i run your code
    i need only 1000
    ??
    I get 1000 when I run the program whose source code I showed. If you get the leading zeroes, it implies that you are not running my most recent example.

    More importantly, you need to understand what the code commented by "Find the first non-zero." and "Print the significant digits." does.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #33
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    i fixed it

  4. #34
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    why when i put
    Code:
    int digits[50]={9, 1, 100};
    it gives me
    10019
    ??

  5. #35
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    i changed your code to
    Code:
    /* Find the first non-zero. */
        for (i = NUM_DIGITS - 1; i > 0 && digits[i] == 0; --i);
     temp4=i;
        /* Print the significant digits. */
        for (i=49; i >= 0; --i)
        {
    		if (temp4>=i){
            printf("%d", digits[i]);
    		}
        }
        putchar('\n');

  6. #36
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,401
    Quote Originally Posted by transgalactic2 View Post
    why when i put
    Code:
    int digits[50]={9, 1, 100};
    it gives me
    10019
    ??
    What output did you expect?

    Quote Originally Posted by transgalactic2
    i changed your code to
    What do you hope to achieve by making such a change?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #37
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    i expect
    900 +10 +100
    1010

    ??

  8. #38
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,334
    Since the first 9 means 9 and not 900 that seems like a rather silly expectation.

  9. #39
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,401
    Quote Originally Posted by transgalactic2
    i expect
    900 +10 +100
    1010
    This is frustrating. It looks like you cannot decide how you really want to interpret the array.

    At this point I would like to ask what exactly are you trying to do. What is the point of this whole exercise?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #40
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    10^2 10^1 10^0 etc..

  11. #41
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,401
    Quote Originally Posted by transgalactic2
    10^2 10^1 10^0 etc..
    That is too vague.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #42
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,334
    Quote Originally Posted by transgalactic2 View Post
    10^2 10^1 10^0 etc..
    Yes. And since you start at the right......................

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  2. array question...
    By jerrykelleyjr in forum C Programming
    Replies: 14
    Last Post: 11-14-2006, 05:50 PM
  3. question about multidimensional arrays
    By richdb in forum C Programming
    Replies: 22
    Last Post: 02-26-2006, 09:51 AM
  4. Merge sort please
    By vasanth in forum C Programming
    Replies: 2
    Last Post: 11-09-2003, 12:09 PM
  5. Replies: 3
    Last Post: 11-03-2003, 08:55 PM