0

How can i check if a number is a prime number or Not??

I've been looking round over the internet but i still don't understand how i could check if a number is prime or composite using c++! Can someone help me???

10th Nov 2018, 3:45 PM
JustCodeMore
JustCodeMore - avatar
5 Respostas
+ 8
Can you be a little more specific and show us your attempt, it will be easier for us to help you!👍😉
10th Nov 2018, 7:36 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 7
Mad Program You should form a range based on the input from the user. For ex, if user has entered 3 as lower limit and 6 as upper limit then ur range will consist of 3, 4, 5 and 6. After that you can use a loop to iterate over each item of this loop and then check each time on the mentioned algorithm in my previous answer. Hope this will help you !!!
11th Nov 2018, 2:40 AM
Arushi Singhania
Arushi Singhania - avatar
+ 6
I can give you the algorithm. Basically to determine if a no. is prime or not, you have to take an input from the user which is greater than 1. Then, you have to check that if that number is divisible or not by any no. ranging from 2 to one minus that number. For ex, 4 is composite no because it is divisible by 2 in the range (2, 3).
10th Nov 2018, 4:04 PM
Arushi Singhania
Arushi Singhania - avatar
+ 1
Thank you very much, i understand now. But how can we print all prime numbers in a given range?
10th Nov 2018, 4:07 PM
JustCodeMore
JustCodeMore - avatar
+ 1
Arushi Singhania thanks, it really help me. I'm now going to try the implementation ☺
11th Nov 2018, 4:09 AM
JustCodeMore
JustCodeMore - avatar