How can we check the Prime Number with C programing.

Hm... I just want to share something that I have.

Actually, I have some homework for my "Algoritma dan Bahasa Pemrograman" Lecture. It's same as "Programing Language".



OK, let's check this coding.


#include

void main(void){
int bil,i,j,cek;

scanf("%d",&bil);

for(i=1;i<=bil;i++){
cek=0;
for(j=1;j<=bil;j++){
if(i%j==0){
cek++;
}
}
}
if(cek==2){
printf("prima");
}else{
printf("bukan prima");
}
}


Ok, then check this statement to search a Prime Number

3 (Prime Number)

3 mod 1 = 0
3 mod 2 = 1
3 mod 3 = 0

4 (NOT)

4 mod 1 = 0
4 mod 2 = 0
4 mod 3 = 1
4 mod 4 = 0

5 (Prime Number)

5 mod 1 = 0
5 mod 2 = 1
5 mod 3 = 2
5 mod 4 = 1
5 mod 5 = 0

6 (NOT)

6 mod 1 = 0
6 mod 2 = 0
6 mod 3 = 0
6 mod 4 = 2
6 mod 5 = 1
6 mod 6 = 0

So, let's see. The Prime number has 2times modulum equal for 0.
So that the coclusion is "Prime Number just have TWO 0 for modulum". The program contain the command for count how many 0 have for the number's modulum. If just has TWO 0, it's a prime number, if >TWO it's NOT a prime number. !! ^^


0 comments to "How can we check the Prime Number with C programing."

Post a Comment

Category

There is HIMALKOM

There is HIMALKOM
go to

Followers

Web hosting for webmasters