Advertisement
EndymionSpr

Untitled

Feb 14th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 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 ConsoleApplication1
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13.  
  14.  
  15. int liczba, zmienna = 0;
  16. double suma = 0;
  17.  
  18. Console.WriteLine("Ile liczb chcesz wprowadzić: <2:20>");
  19. while (true)
  20. {
  21. if (int.TryParse(Console.ReadLine(), out liczba) && liczba >= 2 && liczba <= 20) break;
  22. else Console.WriteLine("Podaj poprawną liczbę z zakresu <2:20>");
  23. }
  24.  
  25. for (int i = 0; i < liczba; i++)
  26. {
  27. while (true)
  28. {
  29. Console.Write("Podaj liczbę [{0}]= ", i + 1);
  30. if (int.TryParse(Console.ReadLine(), out zmienna)) break;
  31. else Console.WriteLine("Podaj poprawną liczbę całkowitą!");
  32.  
  33. }
  34. suma += zmienna;
  35. }
  36.  
  37. Console.WriteLine("Średnia arytmetyczna z zadanego ciągu liczb wynosi:{0}", suma/liczba);
  38.  
  39. Console.ReadKey();
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement