-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path17_swap.c
41 lines (40 loc) · 1.02 KB
/
17_swap.c
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/***************************************************************************************
NAME : Karthikeyan.V
DATE : 19.06.2021
DESCRIPTION : To write a program to swap two variables by using pass by reference method
OUTPUT : ./a.out
ENTER A NUMBER NUM1 :2
ENTER A NUMBER NUM2 :-10
AFTER SWAPPING,
NUM1= -10
NUM2= 2
DO YOU WANT YOU CONTINUE(y/Y) :n
**************************************************************************************/
#include<stdio.h>
void swap(int *a,int *b);
int main()
{
int a,b;
char choice;
do
{
printf("ENTER A NUMBER NUM1 :");
scanf(" %d",&a);
printf("ENTER A NUMBER NUM2 :");
scanf(" %d",&b);
swap(&a,&b);
printf("AFTER SWAPPING,\nNUM1= %d\nNUM2= %d\n",a,b);
printf("DO YOU WANT YOU CONTINUE(y/Y) :");
scanf(" %c",&choice);
}
while(choice=='y' || choice=='Y');
}
void swap(int *a,int *b)
{
*a=*a^*b; //we get the difference of two numbers
//printf("%d\n",*a);
*b=*a^*b;
//printf("%d\n",*b); //we get the a value to b
*a=*a^*b;
//printf("%d\n",*a); //we get the b value to a
}