Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Programiranje_domaći_1 {
- public partial class Form1 : Form {
- public Form1() {
- InitializeComponent();
- }
- private void dodaj() {
- if(textBox1.Text.Length > 0) {
- listBox1.Items.Add(textBox1.Text);
- textBox1.Text = "";
- }
- }
- private int suma(int[] brojevi, int n) {
- int s = 0;
- for(int i = 0; i < n; i++)
- s += brojevi[i];
- return s;
- }
- private float prosek(int[] brojevi, int n) {
- return (float)suma(brojevi, n) / n;
- }
- private int max(int[] brojevi, int n) {
- int max = brojevi[0];
- for(int i = 0; i < n; i++)
- max = (brojevi[i] > max) ? brojevi[i] : max;
- return max;
- }
- private int min(int[] brojevi, int n) {
- int min = brojevi[0];
- for(int i = 0; i < n; i++)
- min = (brojevi[i] < min) ? brojevi[i] : min;
- return min;
- }
- //Unos dugme
- private void button1_Click(object sender, EventArgs e) {
- dodaj();
- }
- //Klik entera unosi
- private void textBox1_KeyDown(object sender, KeyEventArgs e) {
- if(e.KeyCode == Keys.Enter)
- dodaj();
- }
- //Obrisi izabrano dugme
- private void button2_Click(object sender, EventArgs e) {
- if(listBox1.SelectedIndex != -1)
- listBox1.Items.RemoveAt(listBox1.SelectedIndex);
- }
- //Obrisi sve izabrane dugme
- private void button3_Click(object sender, EventArgs e) {
- int x = listBox1.SelectedItems.Count;
- for(int i = 0; i < x; i++)
- listBox1.Items.Remove(listBox1.SelectedItems[0]);
- }
- //Ocisti dugme
- private void button4_Click(object sender, EventArgs e) {
- listBox1.Items.Clear();
- }
- //Izracunaj dugme
- private void button5_Click(object sender, EventArgs e) {
- int[] izabrani = new int[listBox1.Items.Count];
- int i = 0;
- //Parni radio button
- if(radioButton6.Checked) {
- foreach(string sx in listBox1.Items) {
- int x = int.Parse(sx);
- if(x % 2 == 0)
- izabrani[i++] = x;
- }
- }
- //Neparni radio button
- if(radioButton7.Checked) {
- foreach(string sx in listBox1.Items) {
- int x = int.Parse(sx);
- if(x % 2 == 1)
- izabrani[i++] = x;
- }
- }
- //Svi radio button
- if(radioButton8.Checked) {
- foreach(string sx in listBox1.Items)
- izabrani[i++] = int.Parse(sx);
- }
- //Izabrani radio button
- if(radioButton9.Checked) {
- foreach(string sx in listBox1.SelectedItems)
- izabrani[i++] = int.Parse(sx);
- }
- //Suma radio button
- if(radioButton1.Checked) {
- label2.Text = "Rezultat je: " + suma(izabrani, i);
- }
- //Prosek radio button
- if(radioButton2.Checked) {
- label2.Text = "Rezultat je: " + prosek(izabrani, i);
- }
- //Broj radio button
- if(radioButton3.Checked) {
- label2.Text = "Rezultat je: " + i;
- }
- //Maksimalni radio button
- if(radioButton4.Checked) {
- label2.Text = "Rezultat je: " + max(izabrani, i);
- }
- //Minimalni radio button
- if(radioButton5.Checked) {
- label2.Text = "Rezultat je: " + min(izabrani, i);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement