Guest User

Untitled

a guest
Mar 24th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace metanit_47
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. Console.WriteLine("Введите несколько чисел (нажмите "z" для завершения):");
  14. int d;
  15. int sum = 0;
  16. char ch=' ';
  17. while(ch!='z')
  18. {
  19. d = Int32.Parse(Console.ReadLine());
  20. sum += d;
  21. }
  22. Console.WriteLine("Сумма введенных чисел равна " + sum);
  23. }
  24. }
  25. }
  26.  
  27. Console.WriteLine("Введите несколько чисел (нажмите "z" для завершения):");
  28. var sum = 0;
  29. var input = Console.ReadLine();
  30. while (input != null && input != "z")
  31. {
  32. int number;
  33. if (int.TryParse(input, out number))
  34. sum += number;
  35. input = Console.ReadLine();
  36. }
  37. Console.WriteLine("Сумма введенных чисел равна " + sum);
Add Comment
Please, Sign In to add comment