LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 03-02-2005, 08:05 AM   #1
hubabuba
Member
 
Registered: Jan 2002
Location: UK
Distribution: Slack 12.1, 2.6.24.5
Posts: 185

Rep: Reputation: 30
input single integer value, output the value as separate digits


Hi All!

I can't find any help on how to input single integer value, output the value as separate digits.
I meant to use the remainder and division operators. So if i input 1234, i'd be able to printf it out as 1 2 3 4 or as 4321. I'm not meant to use arrays or anything like that. Please help.

Last edited by hubabuba; 03-02-2005 at 08:07 AM.
 
Old 03-02-2005, 08:15 AM   #2
jtshaw
Moderator
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 63
What is this number % 10? 4. Subtract the remainder. 1230.

What is the new number % 100? 30. Divide by 10 to get 3, Subtract entire remainder to get 1200.

What is the new number % 1000? 200. Divide by 100 to get 3, Subtract entire remainder to get 1000.

What is the new number % 10000? 1000. Divide by 1000 to get 1, Subtract entire remainder to get 0. Your done.

See the pattern?
 
Old 03-02-2005, 10:42 AM   #3
hubabuba
Member
 
Registered: Jan 2002
Location: UK
Distribution: Slack 12.1, 2.6.24.5
Posts: 185

Original Poster
Rep: Reputation: 30
Thanks for help. It is actually straignt forward.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Input/output error rob19 Linux - Newbie 13 02-28-2012 10:23 AM
dd input/output error matazar42 Linux - General 3 10-08-2005 05:22 PM
dd: input/output error? logosys Linux - Newbie 3 09-19-2005 02:13 AM
what is input output error? paschim Linux - Newbie 2 10-24-2004 05:53 PM
Input/Output error arctuniol Linux - Software 2 10-06-2003 05:35 PM


All times are GMT -5. The time now is 03:41 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration