Halaman

Pengikut

Sabtu, 28 November 2009

Prime Number Examination

Now will be to make a number examination program to know is the number included prime number or no. We know that prime number are numbers which remain is not zero if divided by number except 1 and its self. The prime number are 2, 3, 5, 7, 11, 13, 17, 19, ...

A number examination algorithm, is a number constitute prime number or no. The algorithm is as follows.
  1. Suppose that number will be entered is a, then we will examine is a constitute prime number or no. The final answer is a constitute prime number or a is not constitute prime number. Beginning thought is certain the number will be entered fulfill one of three conditions below, that is:
     a is smaller than 2 (a < 2 )
     a is 2 (a = 2)
     a is larger 2 (a > 2)
    Cause we know that prime number begin from 2, then certain all numbers are smaller than 2 are not prime number and 2 is the first prime number, until which need to next examine only numbers are larger than 2, then can make the beginning algorithm as follow.


  2. If a > 2, 2. If a > 2, then we will examine is there number from 2, 3, ..., a-1 which constitute factor of a, if found one or more between 2, 3, ..., a-1 which constitute factor of a then a is not prime number. We consider the number contitute factor of a with b, where b = 2, 3, ..., a-1, and b is said factor of a if and only if a mod b = 0. So, we need to examine as many (a-2) number, then the algorithm be:


If the algorithm above we pour into Pascal programming Leanguage, then will be could sintax like below:

uses crt;
var a,b:longint; j:char;
begin clrscr;
write('input a number which equals or larger than 2 : '); readln(a);
if a<2 then
begin
writeln('Sorry, the number has entered is not suitable with program message,');
writeln('then has certain ',a,' is not prime number');
end;
if a=2 then writeln('2 constitute prime number');
for b:=2 to a-1 do
begin
if a mod b = 0 then
begin
writeln(a,' is not prime number'); b:=a-1;
end else
if b=a-1 then writeln(a,' constitute prime number');
end;
readln
end.

For friends who want the pascal file of this algorithm or file which has extention .pas can donwload it here, so don’t need rewrite in Turbo Pascal again , hehe ^_^

The result of prime number examination which use Turbo Pascal Programming Leanguage is a application or file .exe which can be downloaded here

The .doc file of this post can be downloaded here

Comments :

0 komentar to “Prime Number Examination”

Posting Komentar

 

Copyright © 2009 by coretan sahabat