+ 1

Question is write a c program to print prime numbers up to n and print the largest number in array.

3rd Feb 2023, 6:14 PM
Anish Raj
Anish Raj - avatar
8 Respuestas
+ 2
What is your attempt?
3rd Feb 2023, 8:19 PM
Justice
Justice - avatar
+ 2
Show your attempt so we can help you debug. Via a code bit would be best.
3rd Feb 2023, 8:32 PM
Justice
Justice - avatar
+ 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 ...
4th Feb 2023, 3:48 AM
Ipang
+ 1
Yes but using array is mandatory. But Thank you :))
4th Feb 2023, 3:53 AM
Anish Raj
Anish Raj - avatar
+ 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!
4th Feb 2023, 8:46 AM
Ipang
0
I printed prime number up to n but not the largest one part.. !
3rd Feb 2023, 8:26 PM
Anish Raj
Anish Raj - avatar
0
Hii
5th Feb 2023, 4:14 PM
Neeraj Kharwar
Neeraj Kharwar - avatar