-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram_47.c
More file actions
25 lines (21 loc) · 1011 Bytes
/
Copy pathProgram_47.c
File metadata and controls
25 lines (21 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Program 47: Write a program to swap two numbers without using a third variable (call by reference).
#include<stdio.h>
int swap(int* , int *);
int swap(int *first_term ,int *second_term){
*first_term = *first_term + *second_term ;
*second_term = *first_term - *second_term ;
*first_term = *first_term - *second_term ;
printf("After swapping (inside function), The value of first and second term are %d and %d respectively.\n", *first_term,*second_term);
return 0;
}
int main(){
int first_term , second_term ;
printf("Enter the value of the first number:");
scanf("%d",&first_term);
printf("Enter the value of the Second number:");
scanf("%d",&second_term);
printf("Before swapping , The value of first and second term are %d and %d respectively.\n", first_term,second_term);
swap(&first_term,&second_term);
printf("After swapping (inside main), The value of first and second term are %d and %d respectively.\n", first_term,second_term);
return 0;
}