hi! iam a newbie how can i get the 10th, 100th, 1000th place for example: the interger is 1235, the ones place is 5, the tenth place is 3, the hundreds place is 2, and the thousands place is 1, please help me and how do you program it at least give me an idea;
salvador01 0 Newbie Poster
Recommended Answers
Jump to PostTry working with the modulus operator...Like below
#include <stdio.h> int main(int argc, char**argv) { fprintf(stdout, "%d\n", 12345 % 10); fprintf(stdout, "%d\n", 12345 % 100); fprintf(stdout, "%d\n", 12345 % 1000); return 0; }
This should give you a good start...
Jump to PostConsider the number 123:
while number is greater than 0 one = 123 % 10 number = number/10 //remove the digit in the one's place from the variable number. loop
That's all there is to it. It peels off the digits, one by one, from the right …
Jump to PostJust refer to Adak's posting, he pretty much solves it for you.
Jump to PostAnd I say again...Adak pretty much solves it for you. Please look at his posting.
All 14 Replies
salvador01 0 Newbie Poster
Shankye 36 Junior Poster
salvador01 0 Newbie Poster
gerard4143 371 Nearly a Posting Maven
Shankye 36 Junior Poster
Snehamathur commented: Not easy 4 newbie +0
Adak 419 Nearly a Posting Virtuoso
salvador01 0 Newbie Poster
gerard4143 371 Nearly a Posting Maven
salvador01 0 Newbie Poster
Shankye 36 Junior Poster
gerard4143 371 Nearly a Posting Maven
mfaisalm 1 Newbie Poster
sharathg.satya -10 Posting Whiz in Training
sharathg.satya -10 Posting Whiz in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.