int array question

This is a discussion on int array question within the C Programming forums, part of the General Programming Boards category; hi everyone.I want to make a int array which stores imaginary integer like 512 and each digit have a different ...

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    46

    int array question

    hi everyone.I want to make a int array which stores imaginary integer like 512 and each digit have a different adress.Let me give an example since my english not enough to explain it.
    int example_array[3];
    int example_number;
    example_number=512;
    I want to arrange it like example_number[0]=5 example_number[1]=1 and example_number[2]=2.
    Is it possible ?

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,057
    Looks like you need a char [] instead of an int [].

  3. #3
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Sounds like you're looking for something like this:
    Code:
    int n = 512;
    int a[10];
    int i = 0;
    while (n > 0) {
        a[i++] = n % 10;
        n /= 10;
    }
    However, this has the digits in the opposite order than you've shown. And note that you'd have to change this somewhat to work for n <= 0.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 12
    Last Post: 11-21-2010, 09:46 AM
  2. Array question.
    By silhoutte75 in forum C++ Programming
    Replies: 5
    Last Post: 11-21-2007, 11:54 PM
  3. Array question..
    By snapshooter in forum C++ Programming
    Replies: 14
    Last Post: 11-24-2004, 09:06 AM
  4. question about array's
    By ChrisE in forum C++ Programming
    Replies: 6
    Last Post: 03-04-2002, 11:56 AM
  5. array question
    By ProLin in forum C++ Programming
    Replies: 5
    Last Post: 01-21-2002, 05:52 PM

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