Skip to content

Commit a72b1c3

Browse files
authored
Create Number swap using Functions
1 parent 0e1685d commit a72b1c3

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Number swap using Functions

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Humza Khawar BS CS 10-C (343114)
3+
Number Swap through functions
4+
5+
*/
6+
7+
#include<stdio.h>
8+
9+
void swap(int x, int y, int* swap1, int* swap2); //this function swaps the number
10+
11+
12+
int main() {
13+
int x, y;
14+
printf("\n Enter First Number : ");
15+
scanf_s("%d", &x);
16+
printf("\n Enter Second Number : ");
17+
scanf_s("%d", &y);
18+
swap(x, y , &x ,&y);
19+
20+
printf(" \n After swap \n First Number = %d , Second Number = %d\n\n", x, y);
21+
return 0;
22+
}
23+
24+
void swap(int x, int y , int* swap1 ,int* swap2)
25+
{ //c1 & c2 are a temporary variables
26+
int c1 = x, c2 = y;
27+
*swap1 = c2;
28+
*swap2 = c1;
29+
30+
}
31+
32+

0 commit comments

Comments
 (0)