Yes that's true. I forgot about the semicolon. I had it right when using the terminal to compile it so it did compile. But the code you just wrote still says segmentation error.
Printable View
Yes that's true. I forgot about the semicolon. I had it right when using the terminal to compile it so it did compile. But the code you just wrote still says segmentation error.
nevermind. Thanks.
ok so now it executes but it gives a lot of numbers all randomly which i don't really understand why. I'm trying to write code to do the summation of x[k] * y[j-k] from k=max(j-9,0) to min(9,j) and calling this array z[j]. I have to write a program that reads the input for x and y arrays from the input file and compute the z array. The program is suppose to print every element of array z. And j=0,1,2,....,18.
The input file contains three values: (1) index of the array, i; (2) value of element i in array x, x[i]; and (3) value of element i in array y, y[i];
the value of x and y elements for undefined indices are assumed to be zero.
I think I am really close. Maybe you can help me fill in the missing code that i need.
Why do you want to compute z every time? Do you need to compute it every time? Why wouldn't you just compute once after you read all the numbers in?
Perhaps by you, but not by anyone (or anything) else. If you need them to be zero, set them to zero.Quote:
the value of x and y elements for undefined indices are assumed to be zero.
Yeah i have to compute the z array for z[1], z[2], z[3], and so on until z[18].
And I can set them to zero after I get the program to do what I want it to do.
Yes, but you can't compute until you read all the data in. And z and x and y must all be the same size; 10 or 19 doesn't matter to me, but you'll have to pick one.
why do they have to be the same size? I'm just giving you what the assignment states. It states that x is size 10, y is size 10, and z is size 19.
Because computing z[15] (say) requires y[15] to exist (when j = 0 in your formula, you will then try to multiply it by y[15] -- and therefore y[15] must exist, which means that y has to be declared as at least that size).
No cause its x[k] and y[j-k] so when j is 15, then k is j-9 which gives 6 so its x[6]*y[9] = z[15]
Well, yes, so your code posted does. And if you run that code you would get
which isn't a segmentation fault, although it does show that you failed to initialize your array of z's to zero before you started.Code:array z[1] is 2.000000
array z[2] is 3.000000
array z[3] is 4.000000
array z[4] is 122176384420437770000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000
array z[5] is 2278088.760784
array z[6] is 121297690267566810000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000
array z[7] is 122172951969028870000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000
array z[8] is 23162634409391300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000
array z[9] is 10.000000
array z[10] is 27601030745683142000000000000000000000000.000000
array z[11] is 8.000000
array z[12] is 5302421546766900900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000
array z[13] is 6.000000
array z[14] is 5.000000
array z[15] is 4.000000
array z[16] is 3.000000
array z[17] is 2.000000
array z[18] is 122176384420437770000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000
I don't get that. I get it doing the same thing over and over again in a loop having z[0] = 1 and then z[0] = 2 and so forth until z[0] = 10. Which i really don't get.
That's because I took it out of the loop, because I would guess it doesn't belong there.
what did you take out of the loop?
The calculation of z. You wouldn't want to do a convolution with incomplete data, I wouldn't think.
I'm confused. What data is incomplete? And taking it out of the loop doesn't do anything. Do i have to take it out of both of the loops? Or out of the while loop completely?