有一个程序运行结果没看懂,大家帮忙看下
该程序由两部分组成:第一部分为
程序代码:#include<stdio.h>
void report_count();
void accumulate(int k);
int count=0; //文件作用域,外部链接
int main(void)
{
int value; //自动变量
register int i;//寄存器变量
printf("Enter a positive integer(0 to quit): ");
while(scanf("%d",&value)==1 && value>0)
{
++count; //使用文件作用域变量
for(i=value; i>=0; i--)
accumulate(i);
printf("Enter a positive integer(0 to quit): ");
}
report_count();
return 0;
}
void report_count()
{
printf("Loop executed %d times\n",count);
}第二部分为:
程序代码:#include<stdio.h>
extern int count; //引用申明,外部链接
static int total=0; //静态定义,内部链接
//void accumulate(int k); //原型
void accumulate(int k) //k具有代码块作用域、空连接
{
static int subtotal=0; //静态、空连接
if(k<=0)
{
printf("llp cycle: %d\n",count);
printf("subtotal: %d; total: %d\n",subtotal,total);
subtotal=0;
}
else
{
subtotal+=k;
total+=k;
}
}运行截图为:主要是结果感觉与程序对不上。






