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

what is a function prototype?

1 Answers  


Given an unsigned integer, find if the number is power of 2?

5 Answers  


Explain how can you tell whether two strings are the same?

0 Answers  


Why can’t we compare structures?

0 Answers  


what is difference between userlevel threads and kernel level threads ?what are the trades offs between these two approaches ? what approach is most frequently used and why ?

1 Answers  






What is null in c?

0 Answers  


Explain what are multibyte characters?

0 Answers  


What is the use of c language in real life?

0 Answers  


what is the use of ~ in c lang?????

3 Answers  


increment operateor (++)and decrament(--) #include<stdio.h> #inclide<conio.h> main() { int x=15; while(x!=0) scanf("%d",&x); {

2 Answers   HCL, Syntel, TCS,


what is linkage error when it occurs in c program

3 Answers  


program to print circle structure

1 Answers  


Categories