-
Notifications
You must be signed in to change notification settings - Fork 1
/
7 - swap two numbers.c
37 lines (33 loc) · 1.05 KB
/
7 - swap two numbers.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
/******************************************************************************
***
*** Functions practice ***
*****
author : Abla-Ouh
Exercice : Write a program in C to swap two numbers using function
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
void swap(int a , int b)
{
int aux;
printf("enter a = "); scanf("%d",&a);
printf("enter b = "); scanf("%d",&b);
//======= Method 1 : Using a temp variable (aux) ==============
aux = a;
a = b;
b = aux;
//=============================================================
/*
//======= Method 2 : without a temp variable ========
a = a - b;
b = a + b;
a = b - a;
//==================================================*/
printf("a = %d\nb = %d",a,b);
}
int main()
{
int a ,b;
swap(a,b);
return 0;
}