A program calculating sequence
Hello
I did a on-line judge problem and the error msg is "segmentation fault"
But the code goes well in my NB, using DEV-C++ 4.9.9.2.
Could somebody give me some hints?
Thanks a lot!
Spec.
1. Input number of sequence
2. Input sequence of 4 elements
3. Determine they are arithmetic or geometric sequence
4. Calculate the 5th element and print the sequences
Sample Input
2
1 2 3 4
1 2 4 8
Sample Output
1 2 3 4 5
1 2 4 8 16
Code:
#include <stdio.h>
#include <memory.h>
int main(void){
int LoS=5;
unsigned int n=0,*S[n],i,j;
while(scanf("%d",&n) != EOF){
for(i=0;i<n;i++){
S[i] = (int*)malloc(LoS*sizeof(int));
}
for(i=0;i<n;i++){
scanf("%d %d %d %d",&S[i][0],&S[i][1],&S[i][2],&S[i][3]);
}
for(i=0;i<n;i++){
if((S[i][1]-S[i][0])==(S[i][2]-S[i][1])){
S[i][LoS-1] = S[i][LoS-2]+(S[i][1]-S[i][0]);
for(j=0;j<LoS;j++) printf("%d ",S[i][j]);
}
else{
S[i][LoS-1] = S[i][LoS-2]+(S[i][1]/S[i][0]);
for(j=0;j<LoS;j++) printf("%d ",S[i][j]);
}
printf("\n");
}
}
getchar();
return 0;
}