Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# 1) what is the algorithm to check whether an entered number is odd / even using C programming

Posted on 2008-10-21
Medium Priority
939 Views
1) what is the algorithm to check whether an entered number is odd / even using C programming
0
Question by:agcps
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 3
• 2

LVL 7

Accepted Solution

Norush earned 1500 total points
ID: 22765552
http://www.cprogramming.com/tutorial/modulus.html
``````#include <iostream>

using namespace std;

int main()
{
int num;
cin >> num;
// num % 2 computes the remainder when num is divided by 2
if ( num % 2 == 0 )
{
cout << num << " is even ";
}

return 0;
}
``````
0

LVL 29

Expert Comment

ID: 22765557
I'm sure you'll get the anwser once the C-heads have woken up but until then....
in words: (my C is rusty)...

if (number modulus 2) equals 1 then
number is odd
else
number is even
end if

heres a gues (may be a mixture of java,C,c++)...
isodd (int number) bool
{
if   (  (number ^2) == 1) then
return true;
else
return (false);
end if
}
0

LVL 6

Expert Comment

ID: 22765558
1) Input a no.
2) If a no. is divided by zero then return Even
3) If a no. is not devided by zero then return Odd.
4) End

0

LVL 7

Expert Comment

ID: 22765569
You use the modules function for this:
The next line does the actual trick:

if ( num % 2 == 0 )
0

LVL 29

Expert Comment

ID: 22766052
yes its % not ^ that I used

so its really....
bool Isodd (int number)

{
if   (  (number % ) == 1) then
return (1);
else
return (0);
end if
retuen 0;
}
0

LVL 7

Expert Comment

ID: 22784796
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even finâ€¦
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
###### Suggested Courses
Course of the Month9 days, 12 hours left to enroll