+ 1

What is the simplest algorithm to check whether a no. is prime or not?

how to check a given no. is prime or not? what are the logics? how to write a program for this

6th Feb 2017, 6:05 AM
Silan Pradhan
Silan Pradhan - avatar
2 Answers
+ 3
#include <iostream> int main() { int number; std::cout << "Enter any desired number: "; std::cin >> number; int x = 1, count = 0; while (true) { if (number % x == 0) { count++; if (count < 3 && x >= number) { std::cout << number << "Prime number" << std::endl; break; } else if (count >= 3) { std::cout << number << "Not a Prime number" << std::endl; break; } } x++; } return 0; }
6th Feb 2017, 11:28 AM
Ashutosh Saraf
Ashutosh Saraf - avatar
+ 1
watch my last code
6th Feb 2017, 6:41 AM
Kawaii
Kawaii - avatar