By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,819 Members | 1,459 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,819 IT Pros & Developers. It's quick & easy.

TWISTER: Add 2 numbers using "SINGLE" variable

P: n/a
Hi,

Can you add two numbers using a Single Variable? :-)
If yes then show me the code!!!

Regards
Nirjhar

Nov 23 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Nirjhar Oberoi wrote:
Can you add two numbers using a Single Variable? :-)
If yes then show me the code!!!
int main (void) {
int v;
v = 2 + 3;
return 0;
}

--
Thad
Nov 23 '06 #2

P: n/a
Thad Smith wrote:
Nirjhar Oberoi wrote:
>Can you add two numbers using a Single Variable? :-)
If yes then show me the code!!!

int main (void) {
int v;
v = 2 + 3;
return 0;
}
Note that the "Single Variable" [sic] is not required:
int main(void)
{
2 + 3; /* evaluate and discard result */
return 0;
}
Nov 23 '06 #3

P: n/a
Martin Ambuhl <ma*****@earthlink.netwrites:
Thad Smith wrote:
>Nirjhar Oberoi wrote:
>>Can you add two numbers using a Single Variable? :-)
If yes then show me the code!!!
int main (void) {
int v;
v = 2 + 3;
return 0;
}

Note that the "Single Variable" [sic] is not required:
int main(void)
{
2 + 3; /* evaluate and discard result */
return 0;
}
It's required to meet the specification (which I suspect has little to
do with the actual requirement).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 23 '06 #4

P: n/a
Martin Ambuhl wrote:
Thad Smith wrote:
>Nirjhar Oberoi wrote:
>>Can you add two numbers using a Single Variable? :-)
If yes then show me the code!!!

int main (void) {
int v;
v = 2 + 3;
return 0;
}

Note that the "Single Variable" [sic] is not required:
int main(void)
{
2 + 3; /* evaluate and discard result */
return 0;
}
While not required to add two numbers, it was stated as a requirement by
the OP, who stipulated a single variable. I debated about whether the
provided code "used" a "Single Variable" to perform the summation (as
opposed to holding the sum). Perhaps I should have written
v = 2;
v += 3; /* v is used to sum two numbers */

--
Thad
Nov 23 '06 #5

P: n/a
Keith Thompson wrote:
Martin Ambuhl <ma*****@earthlink.netwrites:
>Thad Smith wrote:
>>Nirjhar Oberoi wrote:
Can you add two numbers using a Single Variable? :-)
If yes then show me the code!!!
int main (void) {
int v;
v = 2 + 3;
return 0;
}
Note that the "Single Variable" [sic] is not required:
int main(void)
{
2 + 3; /* evaluate and discard result */
return 0;
}

It's required to meet the specification (which I suspect has little to
do with the actual requirement).
Nothing in the specification requires the sum to be stored.
Nov 23 '06 #6

P: n/a
Martin Ambuhl wrote:
Keith Thompson wrote:
>Martin Ambuhl <ma*****@earthlink.netwrites:
>>>Nirjhar Oberoi wrote:
Can you add two numbers using a Single Variable? :-)
If yes then show me the code!!!
int main(void)
{
2 + 3; /* evaluate and discard result */
return 0;
}

It's required to meet the specification (which I suspect has little to
do with the actual requirement).

Nothing in the specification requires the sum to be stored.
The specification does require a single variable to be used,
however, and your code does not use a single variable.

Nov 23 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.