menentukan 10 bilangan prima pertama

#include
#include
int isprima(int n)
{
int li;
if (n == 2)
return 1;
if (n % 2 == 0 || n == 1)
return 0;
for(li = 3;li <= sqrt(n);li+=2)
{
if (n%li == 0)
return 0;
}
return 1;
}
void main(void)
{
int li;
printf("NAMA ; Ahmad Tamimi F");
printf("\nKelas: TI2C");
printf("\nNIM : 108091000076\n\n");
printf("10 Bilangan prima pertama\n\n");
for(li = 1;li<=30;li++)
if (isprima(li))
printf("%3d",li);
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: