Find largest prime number k of array 1

I'm having this problem.
While finding the primes , I do not know how to make it into one array so that...
Your problem is not clear. Please show what you are trying to do.
Find kth largest element

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>

using namespace std;
void Input_Array(int a[],int n)
{
	srand(time_t(NULL));
	for(int i = 0; i < n;i++)
	{
		a[i] = rand() % 90;
	}
}

void Print_Array(int a[],int n)
{
	for(int i = 0; i < n; i++)
	{
		cout<<"   "<<a[i];
	}
}

void Swap(int &x , int &y)
{
	int temp = x;
	x = y;
	y = temp;
}

int Search_Print_k(int a[],int n,int k)
{
	int vt = -1;
	int temp = 0;
	if(k<=n && k>0)
	{
		for(int i = 0;i < n;i++)
		{
			for(int j = i+1; j < n; j++)
			{
				if(a[i] > a[j])
					swap(a[i],a[j]);
			}
			cout<<"   "<<a[i];
			if(a[i] < a[temp])
			{
				k --;
				temp = i;
			}
			if(k == 1)
			{
				vt = i;
				break;
			}
		}
	}
	return a[vt];
}

int main()
{
int a[100],n , k ;
cout<<"\nInput the number of array element : ";
cin>>n;
Input_Array(a,n);
Print_Array(a,n);

cout<<"\nInput k :";
cin>>k;
cout<<"\nElement largest "<<k<<" is : "<<Search_Print_k(a,n,k);
return 0;
}
Are you trying to find prime numbers or largest element? I don't see anything in here that tests primality.
ex:
a = {5 8 1 3 9 6 10}
k = 3
Print >>8
I don't understand that output at all. You're going to have to explain why you want that to happen.
It's a typical heap problem, you can start from this data structure first.
sorry to be on my phone, and hard to write full code, feel free to ping me if you cannot fully understand the heap.
Are you trying to find the kth largest element in the array?

Then just sort the array in descending order and output the kth element.
Topic archived. No new replies allowed.