Guest User

Untitled

a guest
Feb 4th, 2019
1,071
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. /*Write program to enter n numbers and calculate and print their
  2.  exact sum (without rounding).
  3.  ____________________________________________________________
  4.  INPUT                                    OUTPUT
  5.  3                                        1000000000000000015
  6.  1000000000000000000
  7.  5
  8.  10
  9.  ____________________________________________________________
  10.  2                                        333333333333.30000000003
  11.  0.00000000003
  12.  333333333333.3
  13.  ____________________________________________________________
  14.  Hints: Use BigInteger to not lose precision.
  15.  */
  16. using System;
  17. using System.Numerics;
  18.  
  19. namespace _03ExactSumOfRealNumbers
  20. {
  21.     class Program
  22.     {
  23.         static void Main(string[] args)
  24.         {
  25.             int lines = int.Parse(Console.ReadLine());
  26.             decimal sum = 0;
  27.             for (int i = 0; i < lines; i++)
  28.             {
  29.                 decimal num = decimal.Parse(Console.ReadLine());
  30.                 sum += num;
  31.             }
  32.             Console.WriteLine(sum);
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment