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 proiect
- {
- public partial class Form1 : Form
- {
- int n, i = 2, ok, invalid = 0, contor;
- public Form1()
- {
- InitializeComponent();
- }
- public static int primfunctie(int a)
- {
- for (int i = 2; i <= Math.Sqrt(a); i++)
- if (a % i == 0) return 0;
- return 1;
- }
- private void label1_Click(object sender, EventArgs e)
- {
- }
- private void label2_Click(object sender, EventArgs e)
- {
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if ((textBox1.Text) != "")
- {
- n = Convert.ToInt32(textBox1.Text);
- if (n <= 9999 && n >= 0)
- {
- textBox6.Text = "";
- textBox6.Text = " Numarul este valid.";
- }
- else
- {
- textBox6.Text = "";
- textBox6.Text = " Numarul este invalid.";
- MessageBox.Show("Introduceti un numar pozitiv de maxim 4 cifre.");
- invalid = 1;
- }
- }
- }
- private void label3_Click(object sender, EventArgs e)
- {
- }
- private void checkBox2_CheckedChanged(object sender, EventArgs e)
- {
- }
- private void button2_Click(object sender, EventArgs e)
- {
- if (textBox1.Text != "")
- {
- if (invalid == 0)
- {
- n = Convert.ToInt32(textBox1.Text);
- if (primfunctie(n) == 0)
- {
- textBox4.Text = "";
- textBox4.Text = " Nu este numar prim.";
- }
- else
- {
- textBox4.Text = "";
- textBox4.Text = " Este numar prim.";
- }
- }
- else
- {
- textBox4.Text = "";
- textBox4.Text = " Numar invalid.";
- }
- }
- }
- private void button3_Click(object sender, EventArgs e)
- {
- if (textBox1.Text != "") {
- if (invalid == 0)
- {
- if (checkBox1.CheckState == CheckState.Checked)
- {
- i = Convert.ToInt32(textBox1.Text);
- if (i < 3)
- {
- textBox2.Text = "";
- textBox2.Text = " Nu exista.";
- }
- else
- {
- textBox2.Text = "";
- ok = 1;
- while (i > 2 && ok >= 0)
- {
- i = i - 1;
- if (primfunctie(i) == 1 && ok >= 0)
- {
- textBox2.Text = textBox2.Text + " " + Convert.ToString(i);
- ok = ok - 1;
- }
- }
- }
- }
- if (checkBox2.CheckState == CheckState.Checked)
- {
- i = Convert.ToInt32(textBox1.Text);
- if (i > 9967)
- {
- textBox3.Text = "";
- textBox3.Text = " Nu exista.";
- }
- else
- {
- textBox3.Text = "";
- ok = 1;
- while (i <= 9999 && ok >= 0)
- {
- i = i + 1;
- if (primfunctie(i) == 1 && ok >= 0)
- {
- textBox3.Text = textBox3.Text + " " + Convert.ToString(i);
- ok = ok - 1;
- }
- }
- }
- }
- if (checkBox1.CheckState == CheckState.Unchecked && checkBox2.CheckState == CheckState.Unchecked)
- MessageBox.Show("Selectati cel putin o optiune.");
- }
- else
- {
- if (checkBox1.CheckState == CheckState.Checked)
- {
- textBox2.Text = "";
- textBox2.Text = " Numar invalid.";
- }
- if (checkBox2.CheckState == CheckState.Checked)
- {
- textBox3.Text = "";
- textBox3.Text = " Numar invalid.";
- }
- }
- }
- }
- private void button4_Click(object sender, EventArgs e)
- {
- if (textBox1.Text != "")
- {
- if (invalid == 0)
- {
- n = Convert.ToInt32(textBox1.Text);
- textBox5.Text = "";
- if (n < 2)
- {
- textBox5.Text = "";
- textBox5.Text = " Nu exista.";
- textBox7.Text = " ";
- textBox7.Text = " 0 numere.";
- }
- else
- {
- contor = 0;
- for (i = 2; i <= n; i++)
- {
- if (primfunctie(i) == 1)
- {
- textBox5.Text = textBox5.Text + " " + Convert.ToString(i);
- contor = contor + 1;
- }
- }
- textBox7.Text = "";
- textBox7.Text = Convert.ToString(contor) + " numere.";
- }
- }
- else
- {
- textBox5.Text = "";
- textBox5.Text = " Numar invalid.";
- }
- }
- }
- private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
- {
- this.label1.BackColor = System.Drawing.Color.Transparent;
- try
- {
- VisitLink();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Nu s-a putut deschide link-ul.");
- }
- }
- private void VisitLink()
- {
- linkLabel1.LinkVisited = true;
- System.Diagnostics.Process.Start("http://www.pastebin.com");
- }
- private void button5_Click(object sender, EventArgs e)
- {
- textBox1.Text = "";
- textBox2.Text = "";
- textBox3.Text = "";
- textBox4.Text = "";
- textBox5.Text = "";
- textBox6.Text = "";
- textBox7.Text = "";
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void checkBox1_CheckedChanged(object sender, EventArgs e)
- {
- }
- private void label4_Click(object sender, EventArgs e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement