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 many types of linked lists what are they? How many types of data structures?

18 Answers   BSNL, Pivotal Software,


What is auto keyword in c?

0 Answers  


What is openmp in c?

0 Answers  


Does c have an equivalent to pascals with statement?

0 Answers  


Explain why C language is procedural?

0 Answers   GE,






Explain what is the advantage of a random access file?

0 Answers  


How can a program be made to print the line number where an error occurs?

0 Answers  


What are the 5 types of inheritance in c ++?

0 Answers  


`write a program to display the recomended action depends on a color of trafic light using nested if statments

0 Answers  


what is c programming?

3 Answers   TCS,


can we access one file to one directory?

1 Answers  


You have an array of n integers, randomly ordered with value 1 to n-1.The array is such that there is only one and one value occurred twice. How will you find this number?

1 Answers  


Categories