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.Windows.Forms;
- namespace FactorCalc
- {
- public partial class Form1 : Form
- {
- public int NumberInput;
- public bool calcable;
- List<int> results = new List<int>();
- public int r;
- public Form1()
- {
- InitializeComponent();
- DoubleBuffered = true;
- this.MaximizeBox = false;
- }
- private void NEnter_TextChanged(object sender, EventArgs e)
- {
- ValidN.Text = "";
- calcable = true;
- try
- {
- NumberInput = Convert.ToInt32(NEnter.Text);
- }
- catch (FormatException)
- {
- ValidN.Text = "The input is not a sequence of digits.";
- calcable = false;
- }
- catch (OverflowException)
- {
- ValidN.Text = "The input number is too big";
- calcable = false;
- }
- catch
- {
- ValidN.Text = "There was an error!";
- calcable = false;
- }
- }
- private void MCalc_Click(object sender, EventArgs e)
- {
- if (calcable == true)
- {
- Calc.Text = "CALCULATING";
- Application.DoEvents();
- results.Clear();
- ResultBox.Items.Clear();
- for (int i = 1; i <= NumberInput; i++)
- {
- r = NumberInput % i;
- if (r == 0)
- {
- results.Add(i);
- }
- }
- for (int a = 0; a < results.Count; a++)
- {
- ResultBox.Items.Add(results[a].ToString());
- }
- if (results.Count == 2)
- {
- ResultBox.Items.Clear();
- ResultBox.Items.Add(NumberInput.ToString() + " is a prime number");
- }
- Calc.Text = "";
- }
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement