Z
Z
Zhenia Bel2021-11-08 22:18:00
C++ / C#
Zhenia Bel, 2021-11-08 22:18:00

The program does not display the value correctly, how to fix it?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ForConsole1
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, dob =0;
            Console.WriteLine("Введіть діапазон значень");
            Console.WriteLine("Введіть A");
            a = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Введіть B");
            b = Convert.ToInt32(Console.ReadLine());
            for (int i=a; i<=b; i++)
            {
                dob *= i;
            }
            Console.WriteLine($"Добуток = {dob}");
        }
    }
}

618977e24c4b2432651239.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2021-11-08
@defild

int a, b, dob =0;
...
dob *= i;

You can multiply by 0 even until you're blue in the face, it will still be 0. Mathematics of elementary school ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question