- 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 !!!!!đ
3 Answers
+ 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;
}
+ 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;
}
+ 2
https://code.sololearn.com/cstJSbYvdoRR/?ref=app
And this ^ code is in c++