Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace randomgen
- {
- class Vrednost
- {
- public int z;
- public float sr;
- public Vrednost()
- {
- z = 0;
- sr = 0;
- }
- public int zbir(int[] niz, int br_cl)
- {
- for (int i = 0; i <= br_cl - 1; i++)
- {
- z += niz[i];
- }
- return z;
- }
- public float srednja(int[] niz, int br_cl)
- {
- for (int i = 0; i <= br_cl - 1; i++)
- {
- z += niz[i];
- sr = z / br_cl;
- }
- return sr;
- }
- }
- }
- /// FORM
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace randomgen
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- listBox1.Items.Clear();
- if (this.textBox1.Text != "")
- {
- int i = 0;
- Int32.TryParse(textBox1.Text, out i);
- Random rnd = new Random();
- for (int count = 0; count < i; count++)
- listBox1.Items.Add(rnd.Next(i + 1).ToString());
- }
- int r;
- int zb;
- Vrednost suma = new Vrednost();
- r = listBox1.Items.Count;
- int[] brojevi = new int[r];
- for (int i = 0; i < r; i++)
- {
- brojevi[i] = Convert.ToInt32(listBox1.Items[i].ToString());
- }
- zb = suma.zbir(brojevi, r);
- label8.Text = zb.ToString();
- float srednjavred;
- Vrednost srednja = new Vrednost();
- srednjavred = srednja.srednja(brojevi, r);
- label7.Text = srednjavred.ToString();
- label5.Text = brojevi.Max().ToString();
- label6.Text = brojevi.Min().ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement