how to swap four numbers without using fifth variable?
Answers were Sorted based on User's Feedback
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 |
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 |
what is the difference between structure and union?
Can a file other than a .h file be included with #include?
what is the different between data structure and data type?
What is the use of the sizeof operator?
What are structures and unions? State differencves between them.
what does keyword ‘extern’ mean in a function declaration?
What is unsigned int in c?
Explain what are header files and explain what are its uses in c programming?
wap in c to accept a number display the total count of digit
What is double pointer in c?
Write a program that takes a 5 digit number and calculates 2 power that number and prints it.
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