aspire12

3.RoundingNumbers

Feb 7th, 2020
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using static System.Net.Mime.MediaTypeNames;
  4.  
  5. namespace _3.RoundingNumbers
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             //Read an array of real numbers (space separated), round them in "away from 0" style and print the output
  12.  
  13.  
  14.             string input = Console.ReadLine();
  15.             string[] userInputStringArray = input.Split();
  16.             double[] userInputDoubleArray = new double[userInputStringArray.Length];
  17.             for (int i = 0; i < userInputStringArray.Length; i++)
  18.             {
  19.                 userInputDoubleArray[i] = double.Parse(userInputStringArray[i]);
  20.             }
  21.             for (int i = 0; i < userInputDoubleArray.Length; i++)
  22.             {
  23.                 Console.WriteLine($"{Convert.ToDecimal(userInputDoubleArray[i])} => {Math.Round(Convert.ToDecimal(userInputDoubleArray[i]), MidpointRounding.AwayFromZero)}");
  24.             }
  25.            
  26.            
  27.  
  28.            
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment