#include <stdio.h>
main()
{
int a;
int bil_prima;
int testprima();
printf("======================\n");
printf("MENCARI BILANGAN PRIMA\n");
printf("DALAM RENTANG 1-10\n");
printf("======================\n\n");
printf("Bilangan prima yang ditemukan : \n");
for (i=1;i<=10;i++)
{
bil_prima = testprima(i);
if (bil_prima == 1)
{
printf(" %d",i);
}
}
}
int testprima(bil)
int bil;
{
int bagi=3;
int batas;
if (bil == 1)
{
return(0);
} else if (bil==2||bil==3) {
return(1);
} else if (bil % 2 == 0) {
return(0);
} else {
while (batas > bagi)
{
if (bil % bagi == 0)
{
return(0);
break;
}
batas = bil / bagi;
bagi += 2;
}
return(1);
}
}
main()
{
int a;
int bil_prima;
int testprima();
printf("======================\n");
printf("MENCARI BILANGAN PRIMA\n");
printf("DALAM RENTANG 1-10\n");
printf("======================\n\n");
printf("Bilangan prima yang ditemukan : \n");
for (i=1;i<=10;i++)
{
bil_prima = testprima(i);
if (bil_prima == 1)
{
printf(" %d",i);
}
}
}
int testprima(bil)
int bil;
{
int bagi=3;
int batas;
if (bil == 1)
{
return(0);
} else if (bil==2||bil==3) {
return(1);
} else if (bil % 2 == 0) {
return(0);
} else {
while (batas > bagi)
{
if (bil % bagi == 0)
{
return(0);
break;
}
batas = bil / bagi;
bagi += 2;
}
return(1);
}
}
0 comments:
Posting Komentar