problem 57 C sharp

Back to General discussions forum

kuanish.ya     2019-10-13 20:02:03

|It's my cod. and why doesn't it work? I mean, my answer is right, but site doesn't accept. because the expected result has one different answer from the rest. they have 10 values after the point, but one or two have 11 values.

using System;
using System.IO;
class Program24
{
static void Main()
{
    StreamReader art = new StreamReader("C:\\text.txt");
    int data = Convert.ToInt32(art.ReadLine());
    string[] input = art.ReadLine().Replace(".", ",").Split(' ');
    Console.Write(input[0] + " ");
    for (int all = 1; all < data - 1; all++)
    {
        double a = double.Parse(input[all - 1]);
        double b = double.Parse(input[all]);
        double c = double.Parse(input[all + 1]);
        b = (a + b + c) / 3;
        Console.Write("{0:0.##########} ",b);
    }
    Console.Write(input[input.Length - 1] + " ");
}
}
s.ishmuratov     2019-10-14 08:41:05

Hi! Try output your answer this code:

Console.Write(Math.Round(b, 7).ToString().Replace(',','.') + " ");

kuanish.ya     2019-10-14 16:02:07

Hi! Thank you. Your advice really helped. But why is my option wrong because this "," is wrong?

kuanish.ya     2019-10-14 16:18:53

can you hide or delete my code from those who has not done

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