+ 7

Challenge: The Nearest Prime Number

A positive integer n is called a prime number if its only divisors are "1" and "n" itself. Write a program in any language which receives a positive integer from keyboard and finds its nearest prime number(s). Example for n=2 the nearest prime is itself, for n=10 the nearest prime is 11. Note that some numbers, for example 9, have two nearest prime numbers which are 7 and 11.

22nd Oct 2017, 4:24 PM
Vahid Shirbisheh
Vahid Shirbisheh - avatar
8 Respostas
+ 4
Here is my solution in C++: https://code.sololearn.com/cmwxDIiWYfdL
22nd Oct 2017, 11:55 PM
Vahid
Vahid - avatar
+ 7
Since nobody has yet answered my challenged, I decided to write a simple program in Java to initiate the challenge. My method isPrime is the simplest possible (and the most naive) algorithm for checking whether a number is prime or not. Here is my answer to my challenge in Java: https://code.sololearn.com/cp9Zi8r5hqkN
22nd Oct 2017, 4:23 PM
Vahid Shirbisheh
Vahid Shirbisheh - avatar
22nd Oct 2017, 4:51 PM
Maya
Maya - avatar
+ 5
here is my solution for these questions... check it out thanx :) https://code.sololearn.com/cF1b33K4Sg5O/?ref=app
22nd Oct 2017, 5:40 PM
Pranit Gandhi
Pranit Gandhi - avatar
+ 5
@Gordie can you provide link to visit your 2 challenges
22nd Oct 2017, 7:17 PM
Pranit Gandhi
Pranit Gandhi - avatar
+ 3
@Gordie yes I did edit its title :)
22nd Oct 2017, 7:15 PM
Vahid Shirbisheh
Vahid Shirbisheh - avatar
22nd Oct 2017, 9:35 PM
Mostafa Zolfi
Mostafa Zolfi - avatar
+ 1
a whole new refreshing challenge## try it https://www.sololearn.com/discuss/817002/?ref=app
26th Oct 2017, 5:03 PM
sayan chandra
sayan chandra - avatar