Thread View: comp.lang
7 messages
7 total messages
Started by Robert Andrews
Tue, 21 Nov 1995 00:00
I can't figure out how to write this program
Author: Robert Andrews
Date: Tue, 21 Nov 1995 00:00
Date: Tue, 21 Nov 1995 00:00
14 lines
1546 bytes
1546 bytes
Please give help to a Pascal beginner. I'm using TPW 1.5 and I need to write a program that checks whether a given number is exactly divisible by three or not. I will need to input a number and get a report back on if it is or isn't. I can't figure out how I am going to get the program to test this. A program will not be essential from you, but I would like to know the algorithm for the calculation. E-mail would be preferred. Thanks, Robert Andrews robandrews@easynet.co.uk
Re: I can't figure out how to write this program
Author: CLIF PENN
Date: Wed, 22 Nov 1995 00:00
Date: Wed, 22 Nov 1995 00:00
19 lines
1713 bytes
1713 bytes
robandrews@easynet.co.uk (Robert Andrews) wrote: >Please give help to a Pascal beginner. >I'm using TPW 1.5 and I need to write a program that checks whether a >given number is exactly divisible by three or not. >I will need to input a number and get a report back on if it is or >isn't. >I can't figure out how I am going to get the program to test this. >A program will not be essential from you, but I would like to know the >algorithm for the calculation. E-mail would be preferred. >Thanks, >Robert Andrews >robandrews@easynet.co.uk I tried email but my server bounced your address. If N MOD 3 = 0, N is exactly divisible by 3.
Re: I can't figure out how to write this program
Author: Leo Divinagracia III
Date: Wed, 22 Nov 1995 00:00
Date: Wed, 22 Nov 1995 00:00
26 lines
2206 bytes
2206 bytes
Robert Andrews (robandrews@easynet.co.uk) wrote: : Please give help to a Pascal beginner. : I'm using TPW 1.5 and I need to write a program that checks whether a : given number is exactly divisible by three or not. : I will need to input a number and get a report back on if it is or : isn't. : I can't figure out how I am going to get the program to test this. : A program will not be essential from you, but I would like to know the : algorithm for the calculation. E-mail would be preferred. hmmm... just MOD the number by 3. if the result is 0, then it's divisible by 3, i.e. no remainders. if you are not familiar with the MOD function, it does the same thing as the division function, except MOD returns the modulus or the remainder (another fancy term...). in case your compiler doesn't have a MOD function, it's time to get a new one... 8-)) but seriously, the long way to do this is to subtract the INT (y/x) from just (y/x). if the result = 0 then the number is divisble by 3, exactly... -- later days... leo d. ldivinag@s1.csuhayward.edu forward to ldivinag@barney.sbe.csuhayward.edu
Re: I can't figure out how to write this program
Author: Ronnie Lassche
Date: Wed, 22 Nov 1995 00:00
Date: Wed, 22 Nov 1995 00:00
39 lines
2143 bytes
2143 bytes
robandrews@easynet.co.uk (Robert Andrews) wrote:
>Please give help to a Pascal beginner.
>
>I'm using TPW 1.5 and I need to write a program that checks whether a
>given number is exactly divisible by three or not.
>I will need to input a number and get a report back on if it is or
>isn't.
>I can't figure out how I am going to get the program to test this.
>
>A program will not be essential from you, but I would like to know the
>algorithm for the calculation. E-mail would be preferred.
>
>Thanks,
>Robert Andrews
>robandrews@easynet.co.uk
>
Program DivedByThree;
Uses WinCrt;
Var
NumberIn : Integer;
Result : Integer;
Begin
Write ('Give number : ');
ReadLn (NumberIn);
Result := Number Mod 3;
If Result = 0 Then WriteLn (Numberin,' can be diveded by three')
Else WriteLn (NumberIn,' can't be diveded by three');
End.
This little program should do the trick
Ronnie Lassche
Re: I can't figure out how to write this program
Author: Christopher J. Chandra
Date: Wed, 22 Nov 1995 00:00
Date: Wed, 22 Nov 1995 00:00
15 lines
1776 bytes
1776 bytes
write a program that checks whether a given number is exactly divisible by three or not. >I will need to input a number and get a report back on if it is or >isn't. >I can't figure out how I am going to get the program to test this. > >A program will not be essential from you, but I would like to know the >algorithm for the calculation. E-mail would be preferred. input the number divide number by 3 check if modulus > 0, if it is, it is not divisible by 3 if it is not (else), number is divisible by 3 loop until say number=-1 ???
Re: I can't figure out how to write this program
Author: Scott A. Moore
Date: Thu, 23 Nov 1995 00:00
Date: Thu, 23 Nov 1995 00:00
36 lines
2047 bytes
2047 bytes
In article <48t8ub$hld@lemon.easynet.co.uk>, robandrews@easynet.co.uk
says...
>
>Please give help to a Pascal beginner.
>
>I'm using TPW 1.5 and I need to write a program that checks whether a
>given number is exactly divisible by three or not.
>I will need to input a number and get a report back on if it is or
>isn't.
>I can't figure out how I am going to get the program to test this.
>
>A program will not be essential from you, but I would like to know the
>algorithm for the calculation. E-mail would be preferred.
>
>Thanks,
>Robert Andrews
>robandrews@easynet.co.uk
>
program div3(input, output);
var n: integer;
begin
write('Please input the number: ');
readln(n);
writeln;
if (n mod 3) = 0 then writeln('Number is divisible by 3')
else writeln('Number is not divisible by 3)
end.
Note that this is program works for ANY known pascal.
[sam]
Re: I can't figure out how to write this program
Author: Frank Seljee
Date: Thu, 23 Nov 1995 00:00
Date: Thu, 23 Nov 1995 00:00
7 lines
1408 bytes
1408 bytes
Hmmmm, 3. That's an interesting number... You can ad up the individual values of the integer and it still most be divisible by three. Just like this: 12 => 1+2=3 15 => 1+5=6
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads