since few minutes I tried practice "using FOR loop with IF statement" to test user "Even Numbers"(divided / 2) in console screen, I wrote this trivial program to print the statement "IS even number" if the number divided by 2, and print "NOT even number" when not divided by 2, when I tried input a number like "1313" prints "IS even number" although it isn't even number..by calculater 1313/2 = 656.5 ... !
p.s. i want do that without using IF .. ELSE
This is my code:
// write some even numbers | loops and if statement
#include <iostream>
#include <process.h>
using namespace std;
int main()
{
unsigned int n,j;
cout << "Enter a number: ";
cin >> n;
for(j=2; j<=n/2; j++)
if(n%j==0)
{
cout << "IS even number" << endl;
exit(0);
}
cout << "NOT even number" << endl;
return 0;
}