+ 17
[ASSIGNMENT] Swapping Two Variables.
Write a program that swapping variables each other. For Example: Input: v1 = " first string" v2 = " second string" And the output : v2 = " first string" v1 = " second string" Try to slove in short as much as possible. 😊 Good luck.✌✌
25 Answers
+ 3
👉👉👉Next challenge
https://www.sololearn.com/Discuss/1009864/?ref=app
+ 15
Without third variable 😊
https://code.sololearn.com/cfc26oWm4U0p/?ref=app
+ 15
https://code.sololearn.com/cCbmpAa4X4bB/?ref=app
+ 7
https://code.sololearn.com/c2MIch983V19/?ref=app
+ 6
My answer but not shortest
https://code.sololearn.com/ci95iRK2LLBw/#rb
+ 6
My Try In JS ES6:
https://code.sololearn.com/Wm5wt7Fld65w/#js
+ 6
x = 10
y = 1
ruby x,y = y,x
+ 5
Python:
v1,v2 = v2,v1
+ 5
Swapping without using 3rd variable
https://code.sololearn.com/cq88vH4nFgOy/?ref=app
+ 5
how a bout that ?
https://code.sololearn.com/c8Qd4J6r1n15/?ref=app
+ 5
https://code.sololearn.com/cWJOf0k182EA/?ref=app
+ 4
ruby:
v1, v2 = v2, v1
https://code.sololearn.com/cInBoxAUaql8/#rb
and another in c++
https://code.sololearn.com/c7LFXjUimgz4/#cpp
+ 4
we can solve it without using third variable in python. following snippet shows the swapping of two variables.
v1,v2 = v2,v1
+ 4
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("Enter a\n");
scanf("%d",&a);
printf("Enter b\n");
scanf("%d",&b);
printf("The values of a is %d and b is %d before swaping\n",a,b);
c=a; a=b; b=c;
printf("The values of a is %d and b is %d after swaping\n",a,b);
getch();
}
Output:
+ 4
Check this out ☺☺🤘🤘
https://code.sololearn.com/c0AmY28u66Bm/?ref=app
+ 4
https://code.sololearn.com/c5Rs2Nuq0Ph8/?ref=app