Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Manipulate Integers
Author Message

Posted: Sun Mar 30, 2003 10:52 am   Post subject: Manipulate Integers

how can you get the digits from integers... what i want to do is take a number... get the last digit, delete it then subtract it from the whole number...

azndragon

Posted: Sun Mar 30, 2003 11:29 am   Post subject: (No subject)

This is used with the () after calling the variable. You do this:

 code: var number : int var othernumber : string var newnumber : int put "Enter a number" get number othernumber := intstr (number) othernumber := othernumber (length (othernumber) - 1 .. length (othernumber) - 1) newnumber := strint (othernumber) number := number - newnumber put number

Basically, this program converts the input into a string, takes the last letter, converts it back to an integer, and subtracts it from the original number.

Posted: Sun Mar 30, 2003 11:39 am   Post subject: (No subject)

yeah, thats pretty much what i did... i thought there was a way i could do it without converting it to a string... but i guess not eh..
Tony

Posted: Sun Mar 30, 2003 2:00 pm   Post subject: (No subject)

well if its just the last number, you can divide the whole number by 10 then subtract same number rounded down then multiply back by 10...

since the line above doesnt make sence even to myself, I'll just show you the code:

 code: lastDigit := ( (number/10) - floor(number/10) ) * 10
Tony's programming blog. DWITE - a programming contest.
azndragon

Posted: Sun Mar 30, 2003 2:13 pm   Post subject: (No subject)

Yeah, Tony's suggestion works well. I just don't know the shortcuts in programming, but then again, I've only been programming for about 4 months now, maybe experience allows you to learn the good shortcuts.
Tony

Posted: Sun Mar 30, 2003 3:37 pm   Post subject: (No subject)

well its more of being able to look at problem from different perspectives...

while in azndragon's solution he used turings ablitity to turn integer into a string (which he is able to manipulate well)... I used mathimatical approach.

its all about "thinking outside the box" and trying out new ways of doing things. I suppose that comes with experimenting or having a creative mind to begin with. (Note: you'll not get it unless you try it... such as experience is nothing without experimenting)
Tony's programming blog. DWITE - a programming contest.
azndragon

Posted: Sun Mar 30, 2003 4:03 pm   Post subject: (No subject)

tony wrote:
well its more of being able to look at problem from different perspectives...

while in azndragon's solution he used turings ablitity to turn integer into a string (which he is able to manipulate well)... I used mathimatical approach.

its all about "thinking outside the box" and trying out new ways of doing things. I suppose that comes with experimenting or having a creative mind to begin with. (Note: you'll not get it unless you try it... such as experience is nothing without experimenting)

It's kinda ironic that I didn't take the mathematical approach, because if you know me, I'm all math (which is pretty much all programmers should be )
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 7 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: