İşletim Sistemleri (Bahar-2016) Hafta-12

#include<iostream>
#include<pthread.h>

using namespace std;

void* asal(void* arg)
{
	long sayi = (long)(int*) arg;
	int sayac=0;
	for(int i=2;i<(sayi/2)+1;i++)
		if(sayi%i==0)
		{	
			sayac++;
			break;
		}
				
	if(sayac==0)
		cout<<sayi<<" degeri asaldir"<<endl; 
}

void* fib(void* arg)
{
	long sayi = (long)(int*) arg;
	
	int s1=0;
	int s2=1;
	while(s2<sayi)
	{
		int s3=s1+s2;
		s1=s2;
		s2=s3;
		
		if(s2==sayi)
			cout<<sayi<<" degeri fib. sayisidir"<<endl;
	}
}

int main()
{
	pthread_t iplik[2];
	
	pthread_create(&iplik[0],NULL,asal,(void* ) 89 );
	pthread_create(&iplik[1],NULL,fib,(void* ) 89 );
	pthread_join(iplik[0],NULL);
	pthread_join(iplik[1],NULL);
	
}

 

Share