+ 1
Question is write a c program to print prime numbers up to n and print the largest number in array.
8 ответов
+ 2
What is your attempt?
+ 2
Show your attempt so we can help you debug. Via a code bit would be best.
+ 1
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 ...
+ 1
Yes but using array is mandatory. But Thank you :))
+ 1
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!
0
I printed prime number up to n but not the largest one part.. !
0
Hii