# Teaser - 3

 Tweet
6 replies [Last post]
bOtskOOl
Offline
Last seen: 10 years 3 weeks ago
Joined: 2009-02-21
bOt Points: 3500

Teaser 3

Write a program to find and print the given number is odd or even, Using only one printf (output) statement, no conditional Statement and no logical,relational and arithmatic operators.

bOt points to be won  :  30

NOTE::

- Your code should compile and run without errors

aashiqcoolguy21
Offline
Last seen: 9 years 50 weeks ago
Joined: 2009-05-31
bOt Points: 3354
#include <stdio.h> main() {
```#include <stdio.h>
main()
{
int x;
scanf ("%d",&x);
printf   ("%d",x&1);
}```

aashiqcoolguy21
Offline
Last seen: 9 years 50 weeks ago
Joined: 2009-05-31
bOt Points: 3354
#include <stdio.h>main(){
`#include <stdio.h>main(){  int x;  scanf ("%d",&x);  printf   ("%d",x&1);}`

aashiqcoolguy21
Offline
Last seen: 9 years 50 weeks ago
Joined: 2009-05-31
bOt Points: 3354
This an easy to understand

This an easy to understand code. What we have done here is use the bitwise AND operator and use it to bitwise AND the being evaluated number with 1.

The code will print 1 when number is odd and 0 when number is even, which do task in the question quite efficiently.

Offline
Last seen: 10 years 34 weeks ago
Joined: 2009-03-15
bOt Points: 1321
1. Checked considering input

1. Checked considering input even

#include <stdio.h>

main()

{

int n=2;

scanf ("%d",&n);

printf ("If no. is Odd, Output = 1\nIf no. is Even, Output = 0\n Output:\t%d",n&1);

1. Checked considering input odd

#include <stdio.h>

main()

{

int n=1;

scanf ("%d",&n);

printf ("If no. is Odd, Output = 1\nIf no. is Even, Output = 0\n  Output:\t%d",n&1);

aashiqcoolguy21
Offline
Last seen: 9 years 50 weeks ago
Joined: 2009-05-31
bOt Points: 3354
u don hav to use ne

u don hav to use ne mathematical operation adi...... u have used "=" sign... read the instructions yaar ....!!!!

bOtskOOl
Offline
Last seen: 10 years 3 weeks ago
Joined: 2009-02-21
bOt Points: 3500
@aashiqcoolguy

Congratulations you have won this teaser.

BTW '= ' is a assignment operator and is allowed .