Advertisement
ElviraPetkova

Rounding numbers

Feb 4th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.50 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Linq;
  4.  
  5. namespace FundamentalsIntro
  6. {
  7.     public class Program
  8.     {
  9.         public static void Main()
  10.         {
  11.             string textFromNumbers = Console.ReadLine();
  12.             double[] numbers = textFromNumbers.Split().Select(double.Parse).ToArray();
  13.            
  14.             for (int i = 0; i < numbers.Length; i++)
  15.             {
  16.                 double num = numbers[i];
  17.                 int roundedNum = (int)Math.Round(num, MidpointRounding.AwayFromZero);
  18.                 Console.WriteLine("{0} => {1}", num, roundedNum);
  19.             }
  20.  
  21.         }
  22.        
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement