33,321
社区成员




#include <stdio.h>
#define IN
#define OUT
struct result1 {
int addition;
int subtraction;
};
struct result2 {
int multiplication;
int division;
};
OUT struct result1 level1_operation(IN int a, IN int b)
{
struct result1 return_value;
return_value.addition = a + b;
return_value.subtraction = a - b;
return return_value;
}
void level2_operation(IN int a, IN int b, OUT struct result2 *return_value)
{
return_value->multiplication = a * b;
return_value->division = a / b;
}
int main(void)
{
struct result1 r1;
struct result2 r2;
int a = 4, b = 2;
r1 = level1_operation(a, b);
level2_operation(a, b, &r2);
printf("%d + %d = %d\n", a, b, r1.addition);
printf("%d - %d = %d\n", a, b, r1.subtraction);
printf("%d * %d = %d\n", a, b, r2.multiplication);
printf("%d / %d = %d\n", a, b, r2.division);
return 0;
}
typedef struct _res {
float sum;
float dif;
float product;
float quotient;
} res;
res calc(float f1, float f2) {
res r;
r.sum = f1 + f2;
r.dif = f1 - f2;
r.product = f1 * f2;
r.quotient = f1 / f2;
return r; //返回res变量,然后在程序中使用这个返回值就可以了
}
#include "stdio.h"
typedef struct _res {
float sum;
float dif;
float product;
float quotient;
} res;
res calc(float f1, float f2) {
res r;
r.sum = f1 + f2;
r.dif = f1 - f2;
r.product = f1 * f2;
r.quotient = f1 / f2;
return r;
}
int main() {
float f1 = 1.5f;
float f2 = 2.5f;
res r = calc(f1, f2);
printf("%f + %f = %f\n", f1, f2, r.sum);
printf("%f - %f = %f\n", f1, f2, r.dif);
printf("%f * %f = %f\n", f1, f2, r.product);
printf("%f / %f = %f\n", f1, f2, r.quotient);
return 0;
}
--------
1.500000 + 2.500000 = 4.000000
1.500000 - 2.500000 = -1.000000
1.500000 * 2.500000 = 3.750000
1.500000 / 2.500000 = 0.600000