aspose file tools*
The moose likes C / C++ and the fly likes answer for the program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Languages » C / C++
Bookmark "answer for the program " Watch "answer for the program " New topic
Author

answer for the program

karthikeyan ravi
Greenhorn

Joined: Oct 08, 2010
Posts: 1
write a basic program in any language weather its C,C++ ,

when i given an input as 1 it should display 0,if the input is 0 the result should be 1,
the conditions are should not use conditions and arithmetic operators ...?

T Dahl
Ranch Hand

Joined: Oct 07, 2010
Posts: 35
Why not allow conditions or arithmetic?

Would array look-up or substring extraction be allowed?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Hi karthikeyan ravi, welcome to the ranch ! This place is NotACodeMill, so you should DoYourOwnHomework.

Do you mean that it should be in either C or C++ ? If so, I'll move your question to the C/C++ forum.


[My Blog]
All roads lead to JavaRanch
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

Simple substraction can help here. If the input is 1 the output should be 0. If the input is 0 the output should be 1. That means that input + output == 1. I'm sure you can now find out what to assign to the output based on the input.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
T Dahl
Ranch Hand

Joined: Oct 07, 2010
Posts: 35
Rob Prime wrote:Simple substraction can help here. If the input is 1 the output should be 0. If the input is 0 the output should be 1. That means that input + output == 1. I'm sure you can now find out what to assign to the output based on the input.

Subtraction would count as arithmetic, wouldn't it?
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30764
    
156

What about boolean operators?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Steve Fahlbusch
Bartender

Joined: Sep 18, 2000
Posts: 570
    
    7


Easiest way i see would be an array of two elements.

But of course we don't really have a good definition from the OP.

Are conditional opeators allowed?

Or boolean operations?

Or even bit masks?

Once again - hard to say when we do not get the full requirements...
k. mahesh kumar
Greenhorn

Joined: Oct 19, 2010
Posts: 5
//using logical NOT operator
#include<iostream.h>
int main()
{
int a;
cout<<"enter the value i.e 0 or 1"<<endl;
cin>>a;
cout<<"the opposite is"<<!a<<endl;

return 1;
}
Tarun Bolla
Ranch Hand

Joined: Jun 20, 2011
Posts: 89
k. mahesh kumar wrote:
cout<<"the opposite is"<<!a<<endl;
}


I think casting is required here....

cout<<"the opposite is "<<(int) !a<<endl;
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838

T Dahl wrote:
Rob Prime wrote:..

...


Really thought that Rob Spoor is a different one from Rob Prime until now...

SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Gaurav Sagar
Ranch Hand

Joined: Sep 08, 2010
Posts: 97

One of the possible solutions:-


Regards,
Gaurav
Marco Fernandez Galvan
Greenhorn

Joined: Jun 24, 2011
Posts: 3
I have read about you and your book, and I like to be selected by chance I have to do a project for a company, and your book would serve me much help, save me time looking for solutions in the network.

A question I ask you, if you have taken a long time and headaches, writing this book?

A greeting and good luck with the book, and all followers of this forum just to say that cane to keep giving these keyboards.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838

Hi Marco,

As already pointed out here you may have posted your question about the book in its own thread.
Gaurav Sagar
Ranch Hand

Joined: Sep 08, 2010
Posts: 97

One more is using the bitwise exclusive OR operation:-


Regards,

Gaurav
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: answer for the program