标签:段错误
{ int N;
int a[100]={1}; //先初始赋值100年的奶牛数量为1
//定义第N年
a[0]=0;a[1]=1;a[2]=1,a[3]=1; //给数组前四个元素赋值即前四年的奶牛数量都为1
int counter=4;
for(;counter<=100;counter++)
{
a[counter]=a[counter-1]+a[counter-3]; //第四个元素后数组各个元素的关系
}
while(scanf("%d",&N)) //循环输入第N年
{
printf("%d\n",a[N]);
}
}数组a是100长度,但是序号counter<=100,明显越界。如果取消scanf就会出现段错误提示(运行时候的事情)
标签:段错误
原文地址:http://5228690.blog.51cto.com/5218690/1575100