Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...

swap two integer variables without using a third temporary
variable?

Answers were Sorted based on User's Feedback

swap two integer variables without using a third temporary variable?..

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("\n ENTER 2 VALUES : ");
scanf("%d%d",&a,&b);
printf("\n THE VALUES BEFORE SORTING : %d,%d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("\n THE VALUES AFTER SORTING : %d,%d",a,b);
getch();
}

 Is This Answer Correct ? 40 Yes 1 No

swap two integer variables without using a third temporary variable?..

Answer / jigish

b=a*b;
a=b/a;
b=b/a;

simple..try it

 Is This Answer Correct ? 15 Yes 5 No

swap two integer variables without using a third temporary variable?..

the best way what i choose is that : if x=89 , y=-88

x^=y^=x^=y;

this line will swap the above numbers......

thank u

 Is This Answer Correct ? 10 Yes 5 No

swap two integer variables without using a third temporary variable?..

Answer / sumit salve

a=a+b-(b=a);
or
a=a*b/(b=a);
this will also swap two numbers!!!

Thank You...

 Is This Answer Correct ? 0 Yes 0 No

swap two integer variables without using a third temporary variable?..

i'll only give u logic #include<stdio.h>
void main() { int a=10,b=20;
printf("b4 swap:a=%d b=%d",a,b);
a=a+b;b=a-b;a=a-b; printf("aftr
swap:a=%d b=%d",a,b); }
from-onkar.koparde@gmail.com

 Is This Answer Correct ? 2 Yes 4 No

swap two integer variables without using a third temporary variable?..

Answer / abhinav lohar

t=a;
a=b;
b=t;

 Is This Answer Correct ? 0 Yes 8 No

More C Interview Questions

write a c program to calculate the income tax of the employees in an organization where the conditions are given as. (I.T. = 0 if income <100000 I.T = 10% if income _< 200000 it = 20% if income >_ 200000)

What is the difference between constant pointer and pointer to a constant. Give examples.

What are keywords in c with examples?

Print all the palindrome numbers.If a number is not palindrome make it one by attaching the reverse to it. eg:123 output:123321 (or) 12321

C program to find frequency of each character in a text file?

find second largest element in array w/o using sorting techniques? use onle one for loop.

Stimulate calculator using Switch-case-default statement for two numbers

Explain what happens if you free a pointer twice?

the data type used for unlimited value in c and how to do this program

What does sizeof function do?

struct screen_pos{ int row, col } ;move_right(cursor)struct screen_pos *cursor;{ cursor.col++; } /* This statementhas a syntax error */What is the correct statement a) cursor.col = cursor.col + 1; b) col.cursor++; c) *cursor.col++; d) pointer

7-Given an index k, return the kth row of the Pascal's triangle. For example, when k = 3, the row is [1,3,3,1]. For reference look at the following standard pascal’s triangle.

Categories
• C (4646)
• C++ (3462)
• VC++ (653)
• Delphi (566)
• Python Related (3238)
• PHP Related (7341)
• Scala (340)
• R Programming (396)
• Kotlin (184)
• Apache Groovy (39)
• Ruby (245)
• Go Programming Language (139)
• Objective-C (429)
• Programming Languages AllOther (736)