Untitled
unknown
plain_text
a year ago
2.5 kB
9
Indexable
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace zad1 { class wzory //tworze oddzielna tablice, gdzie beda wszystkie procedury do liczenia wzorow { public int[] tab; //tworze tablice, w ktorej z maina pobieram liczby public double srednia, blad, odchylenie; //tworze zmienne opisujace wyniki dzialan public wzory(int[] tab) { this.tab = tab; //służy to do przypisania wartości przekazanych do konstruktora tablicy tab do pola tab obiektu klasy wzory srednia = SredniaAryt(); odchylenie = odchyleniestandardowe(); blad = bladwzgledny(); } private double SredniaAryt() { double mi = 0; double suma = 0; for (int i = 0; i < tab.Length; i++) { suma += tab[i]; } mi = suma / tab.Length; return mi; } private double odchyleniestandardowe() { double suma2 = 0; for (int i = 0; i < tab.Length; i++) { suma2 += (tab[i] - srednia) * (tab[i] - srednia); } suma2 = suma2 / (tab.Length - 1); suma2 = Math.Sqrt(suma2); //tworze pierwiastek return suma2; } private double bladwzgledny() { blad = (odchylenie / srednia) * 100; return blad; } public double getSrednia() //to tworze po to, by poprzez wywolywanie tej metody w mainie, na konsoli wyswietlaly mi sie konkretne wartosci { return srednia; } public double getOdchylenie() { return odchylenie; } public double getBlad() { return blad; } } class Program { static void Main(string[] args) { int[] tab = new int[5] { 1, 2, 3, 4, 5 }; //tworze tablice z konkretnymi wartosciami wzory wzory = new wzory(tab); double srednia = wzory.getSrednia(); double odchylenie = wzory.getOdchylenie(); double blad = wzory.getBlad(); Console.WriteLine("Srednia " + srednia); Console.WriteLine("Odchylenie " + odchylenie); Console.WriteLine("Błąd " + blad); Console.ReadLine(); } } }
Editor is loading...