Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 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 RajakKlase
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. List<int> numbers = new List<int>();
  14. bool stayInLoop = true;
  15. string unosKorisnika;
  16. int unetiBroj;
  17.  
  18. do
  19. {
  20. Console.Write("Unesite broj (ostavi prazno za zavrsetak): ");
  21. unosKorisnika = Console.ReadLine();
  22. if (string.IsNullOrEmpty(unosKorisnika))
  23. {
  24. break;
  25. }
  26. unetiBroj = Convert.ToInt32(unosKorisnika);
  27. numbers.Add(unetiBroj);
  28.  
  29. } while (stayInLoop);
  30.  
  31. Console.WriteLine("Suma svih brojeva je {0}", Suma.CalculateSum(numbers));
  32.  
  33. Console.ReadKey();
  34. }
  35. }
  36. }
  37.  
  38.  
  39.  
  40.  
  41.  
  42. using System;
  43. using System.Collections.Generic;
  44. using System.Linq;
  45. using System.Text;
  46. using System.Threading.Tasks;
  47.  
  48. namespace RajakKlase
  49. {
  50. class Suma
  51. {
  52.  
  53. public static int CalculateSum(List<int> numbers)
  54. {
  55. int brojac = 0;
  56. foreach (int number in numbers)
  57. {
  58. brojac += number;
  59.  
  60. }
  61.  
  62. return brojac;
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement