-
Notifications
You must be signed in to change notification settings - Fork 0
/
Functions.c
53 lines (44 loc) · 993 Bytes
/
Functions.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
#include<stdio.h>
#include<conio.h>
// 1. Swap 2 nos
void swap(int *n1, int *n2);
void main() {
int a, b;
printf("Enter the 2 numbers :");
scanf_s("%d %d", &a, &b);
printf("Before swapping \n\ta : %d : %p \n\tb : %d : %p", a, &a, b, &b);
swap(&a, &b);
printf("\nAfter swapping \n\ta : %d : %p \n\tb : %d : %p", a, &a, b, &b);
}
void swap(int *n1, int *n2) {
int temp = *n1;
*n1 = *n2;
*n2 = temp;
}
// 2. Add 2 nos.
int add(int n1, int n2);
void main() {
int a, b;
printf("Enter the 2 numbers :");
scanf_s("%d %d", &a, &b);
printf("The sum of %d and %d is = %d", a, b, add(a, b));
}
int add(int n1, int n2) {
return n1 + n2;
}
// 3. Return max of 3 nos
int max(int nos[]);
void main() {
int a[3];
printf("Enter the 3 numbers :");
scanf_s("%d %d %d", &a[0], &a[1], &a[2]);
printf("The maximum of %d, %d, %d is = %d", a[0], a[1], a[2], max(a));
}
int max(int nos[]) {
int max = 0;
for (int i = 0; i < 3; i++) {
if (nos[i] > max)
max = nos[i];
}
return max;
}