JIGYASA
Would you like to react to this message? Create an account in a few clicks or log in to continue.
JIGYASA

An online placement forum.


You are not connected. Please login or register

Simple C code

4 posters

Go down  Message [Page 1 of 1]

1Simple C code Empty Simple C code Tue Apr 27, 2010 4:25 pm

i2aGuru



Write a function: fun(int n)
which takes only 1 or 0 as input and returns 0 and 1 respectively.

You have to use only arithmetic operators.

vishal.kapoor



Well here is another way to get this...

int fun(int x){
x = (x+1)%2 ;
}

3Simple C code Empty Re: Simple C code Sat May 01, 2010 2:24 pm

pro



int fun(int n)
{
n?return 0:return 1;
}

4Simple C code Empty @Pro Sun May 09, 2010 8:06 pm

Lucifer


Admin

well your logic is correct but its syntactically wrong.

int fun(int n)
{
n?return 0:return 1; // this is not possible...u will get a compilation error..
}

Correct usage:

int fun(int n)
{
return n?0:1 ;
}



Last edited by Lucifer on Sun May 09, 2010 8:10 pm; edited 1 time in total

https://jigyasa.forumotion.com

5Simple C code Empty @i2aguru Sun May 09, 2010 8:08 pm

Lucifer


Admin

int fun(int x)
{
return 1-x ;
}

https://jigyasa.forumotion.com

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum