+ 1
I need help with my C code.
I stuck with these arrays and pointers. https://code.sololearn.com/cV20S9pk9EB1/?ref=app I need to calculate average value of each row of a 2d array and save it in one new 1d array. I got some outputs like 35982 which are definitely wrong
4 Respuestas
0
https://code.sololearn.com/c2SALiIIUkYf/?ref=app
This should do the trick....
I am a good coder in c but i can tell that using int can give a +-2 error.
If in the end you need integer output only, then cast the array in the end to int before printing
0
My main 2d array should be float as well?
I think averages need floats because it store the result of a division.
Right?
0
Absolutely!!
This happens because division neglects decimal values in case of int datatype.
For eg in an array of 3 values 4, 7 and 10, after division with 3, you're left with 1, 2 and 3. And summing them up you get 6 while your answer should be 7!!
0
Anyhow you can cast the final result to int if you want to avoid the zeroes in the end