EvenOdd

Please support our C# advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2008
Posts: 20
Reputation: arupa is an unknown quantity at this point 
Solved Threads: 0
arupa arupa is offline Offline
Newbie Poster

EvenOdd

 
0
  #1
Aug 15th, 2008
Can you help me to check a number is even or odd without using any conditions.
Arupananda Behera
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: EvenOdd

 
0
  #2
Aug 15th, 2008
Can't!!
Your question has words "OR" this means you've to use a branched code...
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 526
Reputation: selvaganapathy is an unknown quantity at this point 
Solved Threads: 89
selvaganapathy's Avatar
selvaganapathy selvaganapathy is offline Offline
Posting Pro

Re: EvenOdd

 
0
  #3
Aug 15th, 2008
Can you help me to check a number is even or odd without using any conditions.
I think Bitwise & operator can be useful.

No & 2 == 0 means Odd
and
No & 2 == 2 means Even
(here No is any number)

Is this correct?

I think it also using condition but different approach rather than modulus
Selva
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 973
Reputation: Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough 
Solved Threads: 107
Alex Edwards's Avatar
Alex Edwards Alex Edwards is offline Offline
Posting Shark

Re: EvenOdd

 
0
  #4
Aug 17th, 2008
Originally Posted by selvaganapathy View Post
I think Bitwise & operator can be useful.

No & 2 == 0 means Odd
and
No & 2 == 2 means Even
(here No is any number)

Is this correct?

I think it also using condition but different approach rather than modulus
Though zero isn't an even number, it's even enough.

No & 2 == 2 would return false for No = 0.

.
.
.

Modulus wins!
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 526
Reputation: selvaganapathy is an unknown quantity at this point 
Solved Threads: 89
selvaganapathy's Avatar
selvaganapathy selvaganapathy is offline Offline
Posting Pro

Re: EvenOdd

 
1
  #5
Aug 17th, 2008
Though zero isn't an even number, it's even enough.

No & 2 == 2 would return false for No = 0.


Modulus wins!
Yes, I agree
but you can change the condition like

No & 1 == 1 means Odd

otherwise Even
Selva
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 20
Reputation: arupa is an unknown quantity at this point 
Solved Threads: 0
arupa arupa is offline Offline
Newbie Poster

Re: EvenOdd

 
0
  #6
Aug 25th, 2008
}
Console.WriteLine("enter number to check even or odd");
int n=Convert.ToInt32(Console.ReadLine);
string []array=new string[]{"Even","Odd"};
Console.WriteLine(n%2);
}
Arupananda Behera
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1078 | Replies: 5
Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC