-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunds.c
52 lines (43 loc) · 980 Bytes
/
funds.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
#include <stdio.h>
#define FUNDLEN 50
struct funds {
char bank[FUNDLEN];
double bankfund;
char save[FUNDLEN];
double savefund;
};
double sum1(double, double);
double sum2(const struct funds *);
double sum3(struct funds);
int main()
{
struct funds stan = {
"Garlic-Melon Bank",
4032.27,
"Lucky's Savings and Loan",
8543.94
};
printf("Stan has a total if $%.3f.\n", sum1(stan.bankfund, stan.savefund)); //向函数传递结构成员
printf("Stan has a total if $%.3f.\n", sum2(&stan)); //向函数传递结构的地址
printf("Stan has a total if $%.3f.\n", sum3(stan)); //向函数传递结构
return 0;
}
double sum1(double x, double y)
{
return (x + y);
}
double sum2(const struct funds * money)
{
return (money->bankfund + money->savefund);
}
double sum3(struct funds moolah)
{
return (moolah.bankfund + moolah.savefund);
}
/*
output:
Stan has a total if $12576.210.
Stan has a total if $12576.210.
Stan has a total if $12576.210.
--------------------------------
*/