part1
#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);
}
part2
#include<stdio.h>
extern int count;
static int total = 0;
/*void accumulate(int k)*/
void accumulate(int k)
{
static int subtotal = 0;
if (k <= 0)
{
printf("loop cycle:%d\n",count);
printf("subtotal: %d; total ; %d\n",subtotal,total);
subtotal = 0;
}
else
{
subtotal = subtotal + k;
total = total + k;
}
我想问的是part1与part2怎么样链接起来才能运行。
----------------解决方案--------------------------------------------------------
可以建立工程.或者用#include""
----------------解决方案--------------------------------------------------------