c program to check no. is even or odd without using conditional operator !!
#include// in above c code using % operator and array we can find the no. is even or odd also we can perform it by using bitwise AND operato (&) and AND operator (&&).................#include int main() { int no; char ch[0]="Even"; char ch[1]="odd"; printf("Enter a no. \t"); scanf("%d",&no); printf("\n The no. is %s",ch[no%2]); return (0); }
I gave u the hint can anybody is able to write 2nd program ...😉😀//
o/p--> Enter a no. 7
The no. is odd
Enter a no. 4
The no. is Even
Replies
-
Anoop KumarGood program but in wrong category.
You should post computer and IT related stuffs at following section:
#-Link-Snipped-# -
nareshkumar6539
When we use logical and or bit wise first it will convert number into binary format then it will perform the operation.Gaurav v. Deshmukh#include
// in above c code using % operator and array we can find the no. is even or odd also we can perform it by using bitwise AND operato (&) and AND operator (&&).................#include int main() { int no; char ch[0]="Even"; char ch[1]="odd"; printf("Enter a no. \t"); scanf("%d",&no); printf("\n The no. is %s",ch[no%2]); return (0); }
I gave u the hint can anybody is able to write 2nd program ...😉😀//
o/p--> Enter a no. 7
The no. is odd
Enter a no. 4
The no. is Even
When we perform Logical and or Bitwise and operation with NUMBER&&1 it will give
one means it is ODD number it will give 0 means EVEN number.
(NUMBER&&1)?"ODD":"EVEN" or (NUMBER&1)?"ODD":"EVEN" -
rahul69
Logical And will not work! because logical And can only check if the number is non zero, to check even odd, you will have to use bitwise And ie '&'nareshkumar6539When we use logical and or bit wise first it will convert number into binary format then it will perform the operation.
When we perform Logical and or Bitwise and operation with NUMBER&&1 it will give
one means it is ODD number it will give 0 means EVEN number.
(NUMBER&&1)?"ODD":"EVEN" or (NUMBER&1)?"ODD":"EVEN" -
Vinut477 easy ways to find whether a number id odd/even.
#-Link-Snipped-#
You are reading an archived discussion.
Related Posts
I've been using BSNL FTTH service (unlimited 2 Mbps) plan and totally satisfied with the quality of service. My only complaint has been with the tariff BSNL has on the...
Leapmotion has been making news everywhere since its introductory video was launched. But when people had the device delivered to them, there wasn't the right kind of talk that the...
One of the crazy things on internet
In reply, Marisaa Mayer retweeing these tweets 😁
Twitter page: https://twitter.com/marissamayer
hey guys ,
just write any tricy c code ...
as the game everyone will answer it ..
ok 1st my turn,,,
what will be the output of following code...
By shifting the solar panel inside the aerodynamically designed shell, Cambridge University students have upped the ante on the
October’s World Solar Challenge, a gruelling four-day-long, 3,000km race across the...