Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
C++ Assignment..
//Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x64 #include <iostream> using namespace std; int main() { int n,x; bool Y = true; cout << "Even or Odd Numbers\nAlso specifies the Prime Number\n\nEnter any positive integer\n\n"; cin >> n; if (n%2==0) cout << "Dude! Number is Even\n"; else cout << "Dude! Number is Odd\n"; /*This program takes a positive integer from user and stores it in variable n. Then, for loop is executed which checks whether the number entered by user is perfectly divisible by x or not. The for loop initiates with an initial value of x equals to 2 and increasing the value of x in each iteration. If the number entered by user is perfectly divisible by x then, Ans is set to false and the number will not be a prime number. But, if the number is not perfectly divisible by x until test condition x <= n/2 is true means, it is only divisible by 1 and that number itself. So, the given number is a prime number.*/ for(x = 2; x <= n / 2; ++x) { if(n % x == 0) { Y = false; break; } } if (Y) cout << "But this is a prime number\n"; else cout << "But this is not a prime number\n"; return 0; }
run
|
edit
|
history
|
help
0
const_pointer_cast
msvc set-terminate
#26
RecursiveDivide
MyCodeWindows
Data structure alignment
Matrix paths right-down only, going through XY
ToString library for C++
Build char string (multibyte) with wchar
OS_checker