C Hamming number

Posted: October 12, 2014 in Algorithms, C
Tags: ,

Hamming sayıları 2,3,5 ten başka diğer asal bölenleri olmayan dizilere denir.

2 3 4 5 6 8 9 10 12 15 16 18 20 24 25 27 30 32 36 40 ….

Aşağıdaki program girdiğimiz sayıya kadar olan hamming sayılarını bulmaktadır.

#include
#include
#include

int bayram(int x)
{
if(x==1) return 1;
if(x%2==0) return bayram(x/2);
if(x%3==0) return bayram(x/3);
if(x%5==0) return bayram(x/5);
return 0;

}

int hamming(int x)

{

if (x==1) return 1;
hamming(x-1);
if(bayram(x)) printf(” %d “,x);

}

int main()
{

hamming(20);

return 0;
}

—————————————————————————————————————————-

28

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