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 the difference between structure and union?

3 Answers  


Can a file other than a .h file be included with #include?

0 Answers   Aspire, Infogain,


what is the different between data structure and data type?

1 Answers   Ignou,


What is the use of the sizeof operator?

2 Answers  


What are structures and unions? State differencves between them.

0 Answers   iNautix,


what does keyword ‘extern’ mean in a function declaration?

1 Answers   Emerson,


What is unsigned int in c?

0 Answers  


Explain what are header files and explain what are its uses in c programming?

0 Answers  


wap in c to accept a number display the total count of digit

4 Answers  


What is double pointer in c?

0 Answers  


Write a program that takes a 5 digit number and calculates 2 power that number and prints it.

1 Answers  


The program to allow the characters from the input received and send this function to a function check if the characters between letters a to z is a function of y joins as the characters main and output to otherwise return to the original function of the y characters

0 Answers  


Categories