Task 57 Problem in Answer

Back to General discussions forum

Victor Soldera     2020-05-19 23:20:59
User avatar

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!

Quandray     2020-05-20 11:37:26
User avatar

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);

Victor Soldera     2020-05-20 11:48:46
User avatar

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!

Quandray     2020-05-21 06:11:08
User avatar

I don't think it matters. My code had 10.

Please login and solve 5 problems to be able to post at forum