Question is write a c program to print prime numbers up to n and print the largest number in array.
What is your attempt?
Show your attempt so we can help you debug. Via a code bit would be best.
If use of array was optional, you can instead create and use a variable, let's say <largest_prime>. Initialize <largest_prime> value by 2 (smallest prime number) before beginning the loop (at line 9), and start the loop counter <i> by 3 (next prime number following 2) In each iteration of the outer loop, compare and update <largest_prime> as necessary when you found that <i> was a prime number. Does it break output if you reset <brk> before the inner loop? resetting <brk> inside the inner loop seems redundant due to repetition ...
Yes but using array is mandatory. But Thank you :))
Very well. I suppose the use of variable <largest_prime> can still be used in combination with the array-based approach. Or you can simply store the moat recently found prime number in <largest_prime> considering the search increments <i> during the process. Best of luck!
I printed prime number up to n but not the largest one part.. !