how to swap four numbers without using fifth variable?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is switch in c?

638


What is pass by value in c?

591


What is the benefit of using an enum rather than a #define constant?

648


What is infinite loop?

620


What is the use of putchar function?

644






How will you print TATA alone from TATA POWER using string copy and concate commands in C?

916


What are preprocessor directives in c?

628


Why are all header files not declared in every c program?

592


What are the scope of static variables?

595


What is the difference between new and malloc functions?

570


What is the sizeof () a pointer?

541


What is the difference between if else and switchstatement

1307


Is null valid for pointers to functions?

601


In a switch statement, explain what will happen if a break statement is omitted?

620


One of the Institutes contains 5 student groups. Every group contains 4 students. Institute wants to store student group’s details in array. Group should contain group member’s details (name and registration number and age), project name, and mark of the group.

2152