ellapt

4.7.SumOfNnumbers

Dec 7th, 2012
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. using System;
  2. class SumOfNnumbers
  3. {
  4. static void Main()
  5. {
  6. Console.WriteLine("Get n, get more n numbers, calculate and print their sum.");
  7. string inputVar;
  8. uint n;
  9. decimal sum = 0M;
  10. decimal num;
  11. do
  12. {
  13. Console.Write("Enter a positive integer number: ");
  14. }
  15. while(!(uint.TryParse(inputVar=Console.ReadLine(), out n)));
  16. for (int i = 0; i < n; i++)
  17. {
  18. do
  19. {
  20. Console.Write("Enter a number: ");
  21. }
  22. while (!(decimal.TryParse(inputVar = Console.ReadLine(), out num)));
  23. sum += num;
  24. }
  25. Console.WriteLine("The sum of the {0} read numbers is {1}", n, sum);
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment