how to swap four numbers without using fifth variable?

Answers were Sorted based on User's Feedback



how to swap four numbers without using fifth variable?..

Answer / srinija jilugu

#include<stdio.h>
void main()
{
int a,b,c,d;
printf("enter values\n");
scanf("%d %d %d %d",&a,&b,&c,&d);
printf("before swapping\n");
printf("%d %d %d %d",a,b,c,d);
a=(a+b);
b=(a-b);
a=(a-b);
c=(c+d);
d=(c-d);
c=(c-d);
printf("after swapping:%d %d %d %d",&a,&b,&c,&d);
}

Is This Answer Correct ?    23 Yes 19 No

how to swap four numbers without using fifth variable?..

Answer / rocky

#include<stdio.h>
void main()
{
int a,b,c,d;
printf("enter values
");
scanf("%d %d %d %d",&a,&b,&c,&d);
printf("before swapping
");
printf("%d %d %d %d",a,b,c,d);
a=(a+d);
d=(a-d);
a=(a-d);
c=(c+b);
b=(c-b);
c=(c-b);
printf("after swapping:%d %d %d %d",a,b,c,d);
}

Is This Answer Correct ?    5 Yes 5 No

Post New Answer

More C Interview Questions

How can I split up a string into whitespace-separated fields?

0 Answers  


Explain what is wrong with this program statement?

0 Answers  


Explain the difference between null pointer and void pointer.

0 Answers   TCS,


what is the differance between pass by reference and pass by value.

7 Answers   Infosys,


how many error occurs in C language ?

22 Answers   Infosys, Wipro,






What is an example of structure?

0 Answers  


why use "return" statement a) on executing the return statement it immediately transfers the control back to the calling program b) it returns the value present in the parentheses return, to the calling program c) a & b d) none of the above

0 Answers  


What is the process to generate random numbers in c programming language?

0 Answers  


give one ip, find out which contry

4 Answers   Google,


What is identifiers in c with examples?

0 Answers  


multiple of 9 without useing +,* oprator

3 Answers  


What are the two types of functions in c?

0 Answers  


Categories