TWISTER: Add 2 numbers using "SINGLE" variable

N

Nirjhar Oberoi

Hi,

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

Regards
Nirjhar
 
M

Martin Ambuhl

Thad said:
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;
}
 
K

Keith Thompson

Martin Ambuhl said:
Thad said:
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).
 
T

Thad Smith

Martin said:
Thad said:
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 */
 
M

Martin Ambuhl

Keith said:
Martin Ambuhl said:
Thad said:
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.
 
O

Old Wolf

Martin said:
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.
 
Joined
Aug 10, 2010
Messages
1
Reaction score
0
TWISTER: Add 2 numbers using "SINGLE" variable

#include<stdio.h>

int getInt()
{
int a;
scanf("%d",&a);
return a;
}

int main()
{
printf("%d",getInt()+getInt());
return 0;
}

- Md Muzammil
"(e-mail address removed)"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top