+ 2

Swapping of two numbers using functions

2nd Mar 2019, 4:18 AM
Siva Sankar
Siva Sankar - avatar
7 ответов
+ 7
Using function in C, I do not know yet. Without using 3rd var a=2 b=3 a+=b b=a-b a=a-b
2nd Mar 2019, 4:30 AM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 6
>> Using pointers swap(int *a, int *b) { int temp = *a; *a = *b; *b = *a; } int main() { int a, b; cin>>a>>b; swap(&a,&b); return 0; } Or use XOR operator. a = a ^ b; b = a ^ b; a = a ^ b;
3rd Mar 2019, 7:19 AM
Abhishek Tandon
Abhishek Tandon - avatar
+ 1
swapping without using third variable by returning values in c# function swap(x, y) { x, y=y, x return x, y } or in c++ without returning values void swap(int a, int b) { int temp; temp=a; a=b; b=temp; cout<<a; cout<<b; }
3rd Mar 2019, 5:37 AM
Geetanjali Kore
Geetanjali Kore - avatar
+ 1
Void main() { clrscr (); int a, b,temp; cin>>a>>b; temp=a; a=b; b=temp; Cout<<a<<b; getch(); }
3rd Mar 2019, 7:28 PM
Devashish bala
Devashish bala - avatar
0
Thanks my frinds
17th Mar 2019, 5:29 PM
حمزة فاروق
حمزة فاروق - avatar
0
In java public void main (int a, int b){ int temp; temp = x;        x = y;        y = temp;  }
26th Apr 2019, 6:27 PM
Andrew Dodonov
Andrew Dodonov - avatar
- 1
function swap (a,b){ a,b = b,a Return a,b }
2nd Mar 2019, 7:23 AM
Noah Yehualashet
Noah Yehualashet - avatar