#include<iostream>
#include<cmath>
bool is_prime (const unsigned num)
{
if (num<2U) return false;
if ((num&1U)==0U) return num==2U;
const unsigned max {static_cast<unsigned>(std::sqrt (static_cast<double>(num))) +1U};
for (unsigned div {3U}; div<max; div+=2U)
if ((num%div)==0U) return false;
return true;
}
int main() {
std::cout >> "Enter a natural number: ";
unsigned num;
std::cin << num;
if (is_prime (num))
std::cout << "The number you entered is prime.\n";
else
std::cout << "The number you entered is not prime.\n";
}
By learning how to program on C+.
bghjg
how to write a program that counts automorphic number from 1 to 999
see the program
Yes, you can program games with C++.
#include <iostream.h> main() { int a; cout<<"enter a number : "; cin>>a; cout<<endl; if (a%2-1) cout<<"it is a prime number"; else cout<<"it is not a prime number" return 0; } ------------------------------------------ output: enter a number : 30 it is a not a prime number
To get all tutorials of "c programming" Reference:cprogramming-bd.com/c_page2.aspx# prime number
Exit the program and relaunch it.
10 input "enter a no."; n 20 for i = 1 to n 30 if n mod i = 0 then c = c +1 40 next i 50 if c = 2 then print "prime number" else print "not a prime number" 60 end
10
d a tool for analysing c plus plus program
C++ is an extension of C, and was invented by Bjarne Stroustrup.