Run Code

Code Wall

Users

Misc

Feedback

About

Login

Theme

Privacy
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
Please
log in
to post a comment.
find vs at
MSVC initializer code
ambiguity does not count as ambiguity
Say if number is prime and give its factors
CStringA
C++ standard library formatted input hexadecimal float without prefix or exponent test case
C++ quine
Error defining lambda inside namespace
assaa
Template function declaration to avoid usage of template in T::template f<int>()
Please log in to post a comment.