/* EXCHANGE THE INTEGER VALUE WITHOUT USING THE THIRD VARIABLE */
#include<stdio.h>
void main()
{
int a,b;
printf("enter the two integer variabe \n");
scanf("%d,%d",&a,&b);
//exchange the value of a to b ,b to a without using third variable
a=a+b;
b=a-b;
a=a-b;
printf("%d%d",a,b);
getch();
}
/*EXAMPLE: A=3,B=10
A=A+B; // A=3+10=13
B=A-B; //B=3-10=3
A=A-B //A=13-3=10 */
shashikumar s g
15
Light Poster
Recommended Answers
Jump to PostYeah, so? Why would anyone want to do this? It's hard to understand and using a temp variable is clean and understandable.
Jump to Postbut when it comes to memory storage or allocation its better to go in this way,time efficience compare to using the third or temp variable
Really? Please show us why 4 extra bytes for a temp variable is slower than all that math. What are your sources for …
Jump to Postbut when it comes to memory storage or allocation its better to go in this way
Memory footprint is a viable argument, but I'd suggest that if the memory for a variable of type int is too much, you have bigger problems. I'm not sure what you mean …
All 12 Replies
WaltP
2,905
Posting Sage w/ dash of thyme
Team Colleague
shashikumar s g
15
Light Poster
WaltP
2,905
Posting Sage w/ dash of thyme
Team Colleague
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
rithish
13
Junior Poster in Training
rithish
13
Junior Poster in Training
WaltP
commented:
No, he's exchanging. Read the thread AND the code he posted.
-3
thewebhostingdi
-7
Junior Poster
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
shashikumar s g
15
Light Poster
shashikumar s g
15
Light Poster
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
shashikumar s g
15
Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.