-
Notifications
You must be signed in to change notification settings - Fork 1
/
32函数思考练习.c
93 lines (61 loc) · 1.42 KB
/
32函数思考练习.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
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
#include <stdio.h>
int add(int a,int b);
int main(){
//double a= add(3,4);
// printf("%f\n",a);
/*
11.实现一个加法计算器,可以反复使用,当两个要相加的数都为0时,程序退出
思路:
1定义加法函数
2.定义两个变量
3.用scanf()函数接收用户输入
4.调用函数计算得到结果
5.打印输出结果.
6.用循环让用户可以继续下一次输入
7.用if()判断当两个输入的数都为0的时候,程序退出(循环退出break).
while (1) {
printf("请输入两个整数用逗号隔开,可以得到两个数的和\n");
int a;
int b;
scanf("%d,%d",&a,&b);
if(0==a&&0==b){
break;
}
int count=add(a,b);
printf("%d+%d=%d\n",a,b,count);
}
*/
int a;
int b;
while (1) {
printf("请输入两个整数用逗号隔开,可以得到两个数的和\n");
scanf("%d,%d",&a,&b);
if(0==a&&0==b){
break;
}
int count=add(a,b);
printf("%d+%d=%d\n",a,b,count);
}
return 0;
}
int a=2;//全局变量
//1定义加法函数
int add(int a,int b){
return a+b;
}
/*
int add(int b){
if(3==a){
return 0;
}
a++;
printf("haha---\n");
add(3);
return a+b;
}
void hello(){
}
int add(){
return 2;
}
*/