程式如下:
#include <stdio.h>
int main(){
int a;
while(scanf("%d",&a)){
int arr[a];
int boolean[100] = {0};
int count = 0;
for(size_t i=0;i<a;i++){
scanf("%d",&arr[i]);
}
for(size_t i=0;i<a;i++){
for(size_t j=i;j<a;j++){
if(boolean[arr[i]+arr[j]] != 0){
count++;
break;
}
boolean[arr[i]+arr[j]] = 1;
}
}
if(count!=0)printf("It is not a B2-Sequence.\n");
else printf("It is a B2-Sequence.\n");
}
}
想請問為何會有記憶體區段錯誤的問題存在呢?
程式如下:
#include
int main(){
int a;
while(scanf("%d",&a)){
int arr[a];
int boolean[100] = {0};
int count = 0;
for(size_t i=0;i
scanf("%d",&arr[i]);
}
for(size_t i=0;i
for(size_t j=i;j
if(boolean[arr[i]+arr[j]] != 0){
count++;
break;
}
boolean[arr[i]+arr[j]] = 1;
}
}
if(count!=0)printf("It is not a B2-Sequence.\n");
else printf("It is a B2-Sequence.\n");
}
}想請問為何會有記憶體區段錯誤的問題存在呢?
arr[i] + arr[j] 不一定在100以內吧?