-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_calls.c
More file actions
129 lines (90 loc) · 1.91 KB
/
function_calls.c
File metadata and controls
129 lines (90 loc) · 1.91 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// CALL BY VALUE...
#include <stdio.h>
int sum(int a, int b);
int main()
{
int x = 4, y = 7;
printf("the value of x and y is %d\n", sum(x, y));
printf("the value of x and y is %d and %d\n", x, y);
return 0;
}
int sum(int a, int b)
{
int c = a + b;
return c;
}
// .....>> CALL BY REFERENCE.....<
#include<stdio.h>
void swap(int *a , int *b){
int temp;
temp=*a;
*a = *b;
*b = temp;
}
void wrong_swap(int a , int b){
int temp;
temp=a;
a = b;
b = temp;
}
int main(){
int x=3,y=6;
// After wrong swap.
printf("the value of x and y is %d and %d\n" , x,y);
// After swapinf function.
swap(&x,&y);
printf("the value of x and y is %d and %d\n", x,y);
return 0;
}
/*
Write a program using faction while calculate the sum and average of two numbers .
use pointers and print the values of sum and average . in MAIN()
*/
#include <stdio.h>
void sumandavg(int a, int b, int *sum, float *avg)
{
*sum = a + b;
*avg = (float)*sum / 2;
}
int main()
{
int a = 8, b = 6, sum;
float avg;
sumandavg(a, b, &sum, &avg);
printf("the sum is %d\n", sum);
printf("the avg is %f\n", avg);
return 0;
}
/*
Write a programm to chamge the value of a variable to ten times of its current value .
Write a function and pass the value by refrence...
*/
#include<stdio.h>
void change(int *n){
*n= *n * 10;
}
int main(){
int n ;
printf("enter a number: ");
scanf("%d", &n);
change(&n);
printf("the value after chnge is : %d", n);
return 0;
}
/*
Write a programm to chamge the value of a variable to ten times of its current value .
Write a function and pass the value by refrence...
*/
// CALL BY VALUE
#include<stdio.h>
int mult(int n){
int a=n*10;
return a;
}
int main(){
int n;
printf("enter a number is : ");
scanf("%d", &n);
printf("the value after 10 times is %d",mult(n));
return 0;
}