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
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
This isn't the best solution, but I'm lazy
-PreludeCode:#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; }
My best code is written with the delete key.
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?
-PreludeCode:#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; }
My best code is written with the delete key.
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.
Hope is the first step on the road to disappointment.
I have no excuse, I forgot the most elegant way to solve this problem and couldn't stop myself
-Prelude
My best code is written with the delete key.