#include <iostream> 
#include <windows.h>  

using namespace std;
volatile int avgArr; 
volatile int countBig;
volatile int avgValue;

int Arr[100]; 

DWORD WINAPI Calc1(LPVOID N) 
{ 
	cout << "Thread is started." << endl;
	int min=Arr[0];
	int max=Arr[0];

	 for(int i =0;i<(int)N;i++)
	 {
		 if(Arr[i]<min) min = Arr[i];
		 if(Arr[i]>max) max = Arr[i];
		 Sleep(7);
	 }

	cout<< "Min= "<<min<<endl;
	cout<< "Max= "<<max<<endl;

	 for(int i =0;i<(int)N;i++)
	 {
		 Sleep(12);
		 avgValue += Arr[i];
	 }
	 avgValue = avgValue / (int)N;

	 int zCount = 0;
	 int sumPar=0;
	 for(int i=0; i< (int)N; i++)
	 {
		 
		 if(Arr[i] % 2 == 0)
		 {
			 zCount ++;
			 sumPar = sumPar + Arr[i];
		 }
	 }
	 cout << "kilkist parnix =" << zCount << endl; 
	 cout << "suma parnix =" << sumPar << endl; 
	cout << "Thread is finished." << endl; 
	return 0; 
} 
int main() 
{ 
	int n = 10; 
	HANDLE hWorker; 
	DWORD IDWorker; 
 
	cout << "n = "; cin >> n; 

	 for(int i =0;i<n;i++)
	 {
		 cout << "A["<<i<<"]="; cin>>Arr[i];
	 }
	//******************************************************************************
	hWorker = CreateThread(NULL, 0, Calc1, (void*)n, 0, &IDWorker); 
	if (hWorker == NULL) 
	return GetLastError(); 
 	
	// поки потік Calc закінчить роботу
	WaitForSingleObject(hWorker, INFINITE); 
	// закриваємо дескриптор потоку Calc 
	CloseHandle(hWorker);
	//******************************************************************************
	for(int i =0;i<n;i++)
	 {
		 if(Arr[i]>avgValue)
			 countBig++;
	 }
	cout<< "seredne znachenna vsix elementiv= "<<avgValue<<endl;
	cout<< "kilkist elem bilshix za seredne znachenna= "<< countBig <<endl;

	system ("pause");
 	return 0; 
} 
