-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathL12_Functions.c
More file actions
97 lines (84 loc) · 1.15 KB
/
Copy pathL12_Functions.c
File metadata and controls
97 lines (84 loc) · 1.15 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
void functionDemo()
{
printf("Hello");
printf("Hello world");
}
void functionWithArgument(int a,int b,int c, char ch)
{
printf("%d",a);
printf("%c",ch);
}
int functionWithReturn(int a)
{
return a*2;
}
void functionCallByRefrence()
{
int a = 10;
int b = 20;
printf("A Value%d\n",a);
printf("B Value%d\n",b);
//*,&
//a = 100 - 10
//b = 104 - 20
//swapValue(&a,&b);
callByRef(&a,&b);
//a = 100 - 20
//b = 104 - 10
printf("A Value%d\n",a);
printf("B Value%d",b);
}
void callByVal(int a,int b)
{
int c;
c = a;
a = b;
b = c;
}
void callByRef(int *a,int *b)
{
// a - 100 - 10
// b - 104 - 20
int c;
c = *a; // c =10
*a = *b; // a-100 = 20
*b = c; // b-104 = 10
}
void functionWithArray()
{
int array[4] = {1,2,3,4};
printArray(array);
}
// int array[]
void printArray(int *array)
{
printf("%d",*array);
array+=1;
printf("%d",*array);
}
void recursionDemo(int i) //i=1,2,3,4,5
{
printf("%d\n",i);
if(i == 5)
return;
recursionDemo(i+1);
}
void recursionApp(int result,int number)
{
//1 = 1
//2 = 2
//3 = 3*2 = 6
//4 = 4*3*2*1 = 24
//5 = 120
if(number==1)
{
printf("%d",result);
return;
}
//1->5;
//5->4
//20->3
//60->2
//120->1
recursionApp(number*result,number-1);
}