Advertisement
k0mZ

Untitled

May 18th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace randomgen
  7. {
  8. class Vrednost
  9. {
  10. public int z;
  11. public float sr;
  12.  
  13. public Vrednost()
  14. {
  15. z = 0;
  16. sr = 0;
  17. }
  18.  
  19. public int zbir(int[] niz, int br_cl)
  20. {
  21. for (int i = 0; i <= br_cl - 1; i++)
  22. {
  23. z += niz[i];
  24. }
  25. return z;
  26. }
  27.  
  28.  
  29. public float srednja(int[] niz, int br_cl)
  30. {
  31. for (int i = 0; i <= br_cl - 1; i++)
  32. {
  33. z += niz[i];
  34. sr = z / br_cl;
  35. }
  36.  
  37.  
  38.  
  39. return sr;
  40.  
  41.  
  42. }
  43. }
  44.  
  45. }
  46.  
  47.  
  48. /// FORM
  49.  
  50.  
  51.  
  52. using System;
  53. using System.Collections.Generic;
  54. using System.ComponentModel;
  55. using System.Data;
  56. using System.Drawing;
  57. using System.Linq;
  58. using System.Text;
  59. using System.Windows.Forms;
  60.  
  61. namespace randomgen
  62. {
  63. public partial class Form1 : Form
  64. {
  65. public Form1()
  66. {
  67. InitializeComponent();
  68.  
  69.  
  70.  
  71. }
  72.  
  73. private void button1_Click(object sender, EventArgs e)
  74. {
  75.  
  76. listBox1.Items.Clear();
  77.  
  78. if (this.textBox1.Text != "")
  79. {
  80. int i = 0;
  81.  
  82. Int32.TryParse(textBox1.Text, out i);
  83.  
  84. Random rnd = new Random();
  85.  
  86. for (int count = 0; count < i; count++)
  87.  
  88. listBox1.Items.Add(rnd.Next(i + 1).ToString());
  89.  
  90.  
  91. }
  92.  
  93.  
  94.  
  95. int r;
  96. int zb;
  97.  
  98.  
  99.  
  100. Vrednost suma = new Vrednost();
  101.  
  102. r = listBox1.Items.Count;
  103.  
  104.  
  105.  
  106.  
  107. int[] brojevi = new int[r];
  108.  
  109.  
  110. for (int i = 0; i < r; i++)
  111. {
  112. brojevi[i] = Convert.ToInt32(listBox1.Items[i].ToString());
  113. }
  114.  
  115. zb = suma.zbir(brojevi, r);
  116.  
  117. label8.Text = zb.ToString();
  118.  
  119. float srednjavred;
  120.  
  121.  
  122. Vrednost srednja = new Vrednost();
  123.  
  124. srednjavred = srednja.srednja(brojevi, r);
  125.  
  126. label7.Text = srednjavred.ToString();
  127.  
  128. label5.Text = brojevi.Max().ToString();
  129. label6.Text = brojevi.Min().ToString();
  130.  
  131.  
  132.  
  133.  
  134. }
  135.  
  136.  
  137.  
  138. }
  139.  
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement