- 1

Swapping of two numbers.....

Can any of you give me the source code for swapping of two numbers using call by value in C !!!!!😊

27th Nov 2017, 4:02 PM
Aman Jain
Aman Jain - avatar
3 ответов
+ 5
#include <stdio.h> int swap(int* a, int* b){ int temp = *a; *a = *b; *b = temp; } int main() { int n1 = 4; int n2 = 5; printf( "First: %d\nSecond: %d", n1, n2) ; swap(&n1,&n2); printf("After swap:\n" ); printf( "First: %d\nSecond: %d", n1, n2) ; return 0; }
27th Nov 2017, 5:23 PM
Ran Avital
Ran Avital - avatar
+ 3
And if you want without function: #include <stdio.h> int main() { int n1 = 4; int n2 = 5; int temp; printf( "First: %d\nSecond: %d", n1, n2) ; temp = n1; n1 = n2; n2 = temp; printf("After swap:\n" ); printf( "First: %d\nSecond: %d", n1, n2) ; return 0; }
27th Nov 2017, 5:26 PM
Ran Avital
Ran Avital - avatar
27th Nov 2017, 5:26 PM
Ran Avital
Ran Avital - avatar