自由尋覓快樂別人從沒法感受

0%

C语言学习第一章T3

题目:从键盘上输入两个数, 求两个数的和、差、积与商

主要代码:

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
# include <stdio.h>  
int add (float ,float);
int multi (float ,float);
int cut (float ,float);
float division(float ,float);
int main (void)
{
float x,y;
printf("press x,y: \n\n");
scanf("%f%f",&x,&y);
float s1,s2,s3,s4;
s1 = add(x,y);
s2 = multi(x,y);
s3 = cut(x,y);
s4 = division(x,y);
printf("add result:%f \n\n",s1);
printf("multi result:%f \n\n",s2);
printf("cut result:%f \n\n",s3);
printf("division result:%f \n\n",s4);
return 0;
}

int add (float a ,float b)
{
float result;
result = a + b;
return result;
}

int multi (float a ,float b)
{
float result;
result = a * b;
return result;
}

int cut (float a ,float b)
{
float result;
result = a - b;
return result;
}

float division (float a ,float b)
{
float result;
result = (float)a/b ;
return result;
}

运行结果: