Algoritma:
1. For example call the number “ X”
2. Decide the number is even or uneven
3. If the number is even (except: 2), it means that it is not prime number
4. The number only end if divided by 1 and the number itself or not?
5. If not, the number is not prime number
6. If yes, the number is prime number
Program :
01 #include<iostream.h>
|
|
02
03 class prima
|
|
04 }
05 public:
06 prima ();
07 input ();
08 proses ();
09 private;
10 Int bil, batas, x, i;
11 };
12
13 prima::prima ()
14 { cout<< "Menentukan bilangan prima atau bukan "<<endl<<endl;}
15 prima::input()
16 { cout << "Masukkan bilangan : ";
17 cin >> x;
18 cout<<endl;}
19 prima::proses(){
20 batas = 0;
21 for ( i=1; i<=bil; i++)
22 {
23 if (bil%i==0 && X !=0)
25
26 if (batas==2){
27 cout << "Termasuk bilangan prima /n"; }28 else
29 cout << "bukan bilangan /n"; }
30 }31
32 int main ()
33 {
34 prima bilangan;
35 bilangan.input();
36 bilangan.proses ();
37
38 return 0;
39}
|
|
|
|
0 komentar:
Posting Komentar