|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
int count(int);
int main()
{
int x;
while(1)
{
printf("input a number\n");
scanf("%d",&x);
count(x);
if(x==0)
{
break;
}
}
}
int count(int a)
{
int y=0;
if(a!=0)
{
y=y+a;
}
else
{
printf("count is %d\n",y);
return y;
}
}
本帖最后由 zltzlt 于 2020-5-1 12:31 编辑
y 要定义为全局变量。
- #include <stdio.h>
- int y = 0;
- int count(int a);
- int main()
- {
- int x;
- while (1)
- {
- printf("input a number\n");
- scanf("%d", &x);
- count(x);
- if (x == 0)
- {
- break;
- }
- }
- }
- int count(int a)
- {
- if (a != 0)
- {
- y = y + a;
- }
- else
- {
- printf("count is %d\n", y);
- return y;
- }
- }
复制代码
|
|