Back to General discussions forum
Hey! I'am having trouble with the answer of task 57. It seems that the answer matches my code output, but it judges as wrong. Maybe there's a problem that i'm not seeing. Here's the code:
#include <stdio.h>
int main() {
double V[10000];
int N;
scanf("%d", &N);
for(int i = 0; i < N; i++) {
scanf("%lf", &V[i]);
}
for(int i = 0; i < N; i++) {
//Fist member and last member goes to else
if(i != 0 && i != N - 1) {
double x = (V[i - 1] + V[i] + V[i + 1] ) / 3;
printf("%.12g ", x);
}
else
printf("%.1lf ",V[i]);
}
}
Thanks for the help!
Your code worked when I tried it. Maybe it depends on the test data.
I didn't like printf("%.12g ", x); in your code, as that is printing a float not a double.
I'd prefer printf("%.12lg ", x);
Ohh, nice to know, Quadrey! I think i know what happened, there where numbers with spaces. I just have one question. Why I have to put %.12g and not %.10g? Thanks for the help!