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???
5 odpowiedzi
+ 8
Can you be a little more specific and show us your attempt, it will be easier for us to help you!👍😉
+ 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 !!!
+ 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).
+ 1
Thank you very much, i understand now. But how can we print all prime numbers in a given range?
+ 1
Arushi Singhania thanks, it really help me. I'm now going to try the implementation ☺