JIGYASA

An online placement forum.


You are not connected. Please login or register

Simple C code

Go down  Message [Page 1 of 1]

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

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.

View user profile
Well here is another way to get this...

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

View user profile

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

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

View user profile

4 @Pro on 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

View user profile http://jigyasa.forumn.org

5 @i2aguru on Sun May 09, 2010 8:08 pm

Lucifer


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

View user profile http://jigyasa.forumn.org

Sponsored content


Back to top  Message [Page 1 of 1]

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