Run Code

Code Wall

Users

Misc

Feedback

About

Login

Theme
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.
VS struct name enumerate
algorithm_1
1 Girene Kadar Ortalama
Competitive  Algorithm for max number of superior characters
MSVC lambda bug
Integral constant
Strings
amusing overload choice
xyz1_1 programm
fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt
Please log in to post a comment.