# Help me: Display 100's 10's 1's from an integer!

• 03-12-2002
Ramza
Help me: Display 100's 10's 1's from an integer!
Hi, I have a rather simple question.

How can I obtain this result?

---------------------------------

Enter an integer: 283

number of hundreds: 2
number of tens : 8
number of ones : 3

----------------------------------

thank you for your time :)
• 03-12-2002
Prelude
This isn't the best solution, but I'm lazy ;)
Code:

```#include <stdio.h> #include <stdlib.h> int main ( void ) {   int i = 283, j = 2, array[3];   while ( i != 0 ) {     array[j--] = i % 10;     i /= 10;   }   printf ( "%d %d %d\n", array[0], array[1], array[2] );   return EXIT_SUCCESS; }```
-Prelude
• 03-12-2002
Ramza
Thanks for trying but I'ts part of my class project, and we didn't get into arrays yet, so I can't use them.

There must be a simpler way to do this.

Anyone else know how?
• 03-12-2002
Prelude
:D
Code:

```#include <stdio.h> #include <stdlib.h> int main ( void ) {   int i = 283;   printf ( "Number of Ones: %d\n", i % 10 ), i /= 10;   printf ( "Number of Tens: %d\n", i % 10 ), i /= 10;   printf ( "Number of Hundreds: %d\n", i % 10 ), i /= 10;   return EXIT_SUCCESS; }```
-Prelude
• 03-12-2002
quzah
Bah. Prelude, you did their homework for them! For future reference, you (the original poster) should actually read the FAQ, and possibly read the nice little sticky note at the top of the forum. You know the one, the one that said "MAKE AN EFFORT. POST YOUR CODE!" ... Oh forget it. It's a lost cause.

Quzah.
• 03-12-2002
Prelude
I have no excuse, I forgot the most elegant way to solve this problem and couldn't stop myself ;)

-Prelude