Solved

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

Posted on 2008-10-21
6
921 Views
Last Modified: 2013-12-14
1) what is the algorithm to check whether an entered number is odd / even using C programming
0
Comment
Question by:agcps
  • 3
  • 2
6 Comments
 
LVL 7

Accepted Solution

by:
Norush earned 500 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;

}

Open in new window

0
 
LVL 28

Expert Comment

by:chilternPC
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

by:divyeshhdoshi
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 7

Expert Comment

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

if ( num % 2 == 0 )
0
 
LVL 28

Expert Comment

by:chilternPC
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

by:Norush
ID: 22784796
agcps, did you find your answer?
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now