I am practicing c++ and i found this problem extremely difficult. Does anybody know how to find the largest prime number using many elements of an array? No, just an element but generating a prime number with connected elements. Thanks in advance.
That's actually rather easy, this is how I would do it (or rather, this is one of the ways I would think of, not necessarily the best solution, but it works):
1) Write a function is_prime that checks whether a number is a prime number or not.
2) Create a max_prime function that takes a prime number as first argument, and another number as second argument. If the second argument is larger than the first, check with is_prime whether it is a prime number or not. If it is, it returns true, in any other case it returns false.
3) Call std::max_element from the algorithm header with your array and max_prime
This is a very good idea! I 'll try to solve it. Can anyone give me the code or a part of the code of the solution? For example, i would like to find the largest 9-digit prime number of this array:
1 9 4 0 3
7 5 8 3 3
0 0 0 7 9
0 0 0 0 0
9 0 0 1 1
Let's see... first, try to write the is_prime function that checks whether an integer is a prime number. Remember that a prime number is a number that can only be divided by 1 and itself (using integer divisions). I won't give you the full solution cause this is your work- some people here would even disagree with me giving you such detailed steps.
i understand you and that's my first time that i want full solution of my problem but in 2 days i have a competition and that's one of the problems which it might be in the competition...