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

Which node is more powerful and can handle local information processing or graphics processing?

0 Answers  


Software Interview Questions

1 Answers   CAT,


HOW DO YOU HANDLE EXCEPTIONS IN C?

2 Answers   AppLabs,


A marketing company wishes to construct a decision table to decide how to treat clients according to three characteristics: Gender, City Dweller, and age group: A (under 30), B (between 30 and 60), C (over 60). The company has four products (W, X, Y and Z) to test market. Product W will appeal to female city dwellers. Product X will appeal to young females. Product Y will appeal to Male middle aged shoppers who do not live in cities. Product Z will appeal to all but older females.

2 Answers  


How can you invoke another program from within a C program?

0 Answers  


What are disadvantages of C language.

0 Answers   iNautix,


What is a const pointer, and how does it differ from a pointer to a const?

2 Answers  


wats SIZE_T meant for?

1 Answers  


What does %c mean in c?

0 Answers  


What is the difference between the local variable and global variable in c?

0 Answers  


find out largest elemant of diagonalmatrix

0 Answers  


What are the two types of structure?

0 Answers  


Categories