-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path01_swap_values_fun.c
54 lines (43 loc) · 1.17 KB
/
01_swap_values_fun.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
42
43
44
45
46
47
48
49
50
51
52
53
54
// // Write a function to swap strings of two char arrays by calling a functions. (TSRN)
// // Header Files
#include <stdio.h>
#include <conio.h>
// // Functions Declarations (Prototypes)
void swapTwoVal(int *, int *);
// // Main Function Start
int main()
{
int a, b;
printf("\nEnter value of a => ");
scanf("%d", &a);
printf("\nEnter value of b => ");
scanf("%d", &b);
printf("\n\n>>>>>>>>>>> Before Swapping <<<<<<<<<<<\n");
printf("a => %d, b => %d\n", a, b);
// // Swap values of a and b
swapTwoVal(&a, &b);
printf("\n\n>>>>>>>>>>> After Swapping <<<<<<<<<<<\n");
printf("a => %d, b => %d\n", a, b);
putch('\n');
getch();
return 0;
}
// // Main Function End
// // Function to Swap values of two int variables
void swapTwoVal(int *a, int *b)
{
// // using Addition and Subtraction
*a = *a + *b;
*b = *a - *b;
*a = *a - *b;
// // using Divison and Multiplication
// // *a = *a * *b;
// // *b = *a / *b;
// // *a = *a / *b;
// // using Bitwise XOR (^)
// // *a = *a ^ *b;
// // *b = *a ^ *b;
// // *a = *a ^ *b;
// // In Single Statement
// // *a = (*a + *b) - (*b = *a);
}