• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

answer for the program

 
karthikeyan ravi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not allow conditions or arithmetic?

Would array look-up or substring extraction be allowed?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
T Dahl
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34229
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about boolean operators?
 
Steve Fahlbusch
Bartender
Posts: 602
7
Mac OS X Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//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
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
T Dahl wrote:
Rob Prime wrote:..

...


Really thought that Rob Spoor is a different one from Rob Prime until now...
 
Gaurav Sagar
Ranch Hand
Posts: 97
Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of the possible solutions:-


Regards,
Gaurav
 
Marco Fernandez Galvan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marco,

As already pointed out here you may have posted your question about the book in its own thread.
 
Gaurav Sagar
Ranch Hand
Posts: 97
Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more is using the bitwise exclusive OR operation:-


Regards,

Gaurav
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic