Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Pascal Ansi -iso > Re: Turbo Pasca...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 10 of 16 Topic 199 of 215
Post > Topic >>

Re: Turbo Pascal question

by john <john@[EMAIL PROTECTED] > Dec 23, 2007 at 01:33 AM

Jochen wrote:
> 
> do u have to store the digits in a temp array? homework?


It was classwork, and is considered completed. In my original code, I 
had provided a power function myself.


> why not simply make it like this:
> 
> for j := digit_amount downto 1 do
>   result:= result * 10 + temp_array[j];


Interesting. However I can't make it work. Consider the code:

{ A number e.g. 1923=3291 }
program reverse;
uses crt;
var
                i, j, digit_amount, number: longint;
                                temp_array: array[1..5] of longint;
    array_element, result: real;

begin
clrscr;

write('Give the number: ');
readln(number);

i:=0;
while (number div 10)<> 0 do
       begin
       i:=i+1;
       temp_array[i]:= number mod 10;
       number:= number div 10;
       end;

i:= i+1;
temp_array[i]:= number mod 10;

digit_amount:= i;

result:= 0;

{for j:= 1 to i do
     begin
     array_element:= temp_array[j];
     result:= result+ array_element* exp( (digit_amount- j)* ln(10) );
     end;}


for j := digit_amount downto 1 do
   result:= result * 10 + temp_array[j];

writeln;
writeln('The reversed number is: ', result:0:0);

readln;
end.
 




 16 Posts in Topic:
Turbo Pascal question
john <john@[EMAIL PROT  2007-12-20 21:09:11 
Re: Turbo Pascal question
Richard Heathfield <rj  2007-12-20 19:29:28 
Re: Turbo Pascal question
Dr J R Stockton <jrs@[  2007-12-21 13:44:12 
Re: Turbo Pascal question
john <john@[EMAIL PROT  2007-12-22 01:15:05 
Re: Turbo Pascal question
john <john@[EMAIL PROT  2007-12-22 01:38:43 
Re: Turbo Pascal question
Richard Heathfield <rj  2007-12-22 00:58:29 
Re: Turbo Pascal question
john <john@[EMAIL PROT  2007-12-22 13:18:49 
Re: Turbo Pascal question
Richard Heathfield <rj  2007-12-22 11:43:12 
Re: Turbo Pascal question
"Jochen" <jo  2007-12-22 22:42:57 
Re: Turbo Pascal question
john <john@[EMAIL PROT  2007-12-23 01:33:35 
Re: Turbo Pascal question
"Jochen" <jo  2007-12-23 05:56:25 
Re: Turbo Pascal question
scott moore <nospam@[E  2007-12-23 10:33:04 
Re: Turbo Pascal question
john <john@[EMAIL PROT  2007-12-24 00:59:51 
Re: Turbo Pascal question
Dr J R Stockton <jrs@[  2007-12-22 17:51:06 
Re: Turbo Pascal question
john <john@[EMAIL PROT  2007-12-22 20:52:31 
Re: Turbo Pascal question
Dr J R Stockton <jrs@[  2007-12-23 16:36:53 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Jul 23 15:49:59 CDT 2008.