Skip to content

Commit 8032786

Browse files
authored
2.Swap Two Numbers Using Pointers .c
1 parent 172c79b commit 8032786

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

2.Swap Two Numbers Using Pointers .c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <stdio.h>
2+
void swap(int *a, int *b) {
3+
int temp = *a;
4+
*a = *b;
5+
*b = temp;
6+
}
7+
int main() {
8+
int x, y;
9+
printf("Enter two numbers: ");
10+
scanf("%d %d", &x, &y);
11+
printf("Before swapping: x = %d, y = %d\n", x, y);
12+
swap(&x, &y);
13+
printf("After swapping: x = %d, y = %d\n", x, y);
14+
15+
return 0;
16+
}

0 commit comments

Comments
 (0)