This question has already been answered:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Задачи { class Program { static void Main(string[] args) { int n1 = Convert.ToInt32(Console.ReadLine()); int n2 = Convert.ToInt32(Console.ReadLine()); int n3 = Convert.ToInt32(Console.ReadLine()); int sum = n1 + n2 + n3; int pow = n1 * n2 * n3; Double sr = (n1 + n2 + n3) / 3; Console.WriteLine(n1 + "+" + n2 + "+" + n3 + "=" + sum); Console.WriteLine(n1 + "*" + n2 + "*" + n3 + "=" + pow); Console.WriteLine("({0}+{1}+{2})/3={3:#.###}", n1, n2, n3, sr); Console.ReadKey(); } } } 

Reported as a duplicate by the participants Grundy , andreycha , αλεχολυτ , rdorn , Vadim Ovchinnikov Jan 20 '17 at 6:07 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • Retake exam? - Sublihim
  • because if all operands are integer, the division will also be integer. - Grundy

1 answer 1

In this ad

 Double sr = (n1 + n2 + n3) / 3; 

The initialization expression has an integer type, since the variables n1 , n2 and n3 declared to be of type int , and therefore it has no fractional parts.

You could write, for example

 Double sr = (n1 + n2 + n3) / 3.0; 

or

 Double sr = ( double )(n1 + n2 + n3) / 3; 

or as prompted

 Double sr = (n1 + n2 + n3) / 3d; 

The d and D characters in C # are suffixes for numeric literals with a double-precision floating point.

  • or (n1 + n2 + n3) / 3d - Vadim Prokopchuk