I can't find a mistake in my code. When I run it, it says segmentation fault(core dumped). I read topics, but couldn't understand my mistake. It's in appropriate directory. I would be very thankful if some can help me.
#include<stdio.h>
#define MAX 50
int main(){
int i,n,j,t;
double a[MAX];
do{
printf("enter a lenght of your array");
scanf("%d", &n);
}while (n<1 || n>MAX);
printf("enter the elements of your array");
for (i=0; i<n; i++) {
printf("a[%d]= ", i);
scanf("%lf", &a[i]);
}
for(i=0;i<n/2;i++){
for(j=n-1;j>n/2;j++){
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
for(i=0; i<n; i++) {
printf("%lf", a[i]);
}
return 0;
}
i, andn) are not out of bounds (0<=i<MAX).a[i]=a[j];. Still using this debugger (or just add a printf of i and j values) would have shown you that j is always increasing. At at a momenta[j]crashes.