Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.39 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace FactorCalc
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         public int NumberInput;
  15.         public bool calcable;
  16.         List<int> results = new List<int>();
  17.         public int r;
  18.    
  19.  
  20.         public Form1()
  21.         {
  22.             InitializeComponent();
  23.             DoubleBuffered = true;
  24.             this.MaximizeBox = false;
  25.         }
  26.  
  27.         private void NEnter_TextChanged(object sender, EventArgs e)
  28.         {
  29.             ValidN.Text = "";
  30.             calcable = true;
  31.             try
  32.             {
  33.                 NumberInput = Convert.ToInt32(NEnter.Text);
  34.             }
  35.  
  36.             catch (FormatException)
  37.             {
  38.                 ValidN.Text = "The input is not a sequence of digits.";
  39.                 calcable = false;
  40.             }
  41.             catch (OverflowException)
  42.             {
  43.                 ValidN.Text = "The input number is too big";
  44.                 calcable = false;
  45.             }
  46.             catch
  47.             {
  48.                 ValidN.Text = "There was an error!";
  49.                 calcable = false;
  50.             }
  51.            
  52.  
  53.         }
  54.  
  55.         private void MCalc_Click(object sender, EventArgs e)
  56.         {  
  57.             if (calcable == true)
  58.             {
  59.          
  60.  
  61.                 Calc.Text = "CALCULATING";
  62.                 Application.DoEvents();
  63.  
  64.                 results.Clear();
  65.                 ResultBox.Items.Clear();
  66.                 for (int i = 1; i <= NumberInput; i++)
  67.                 {
  68.                    r = NumberInput % i;
  69.  
  70.                     if (r == 0)
  71.                    {
  72.                        results.Add(i);
  73.                        
  74.  
  75.                    }
  76.  
  77.                 }
  78.  
  79.                 for (int a = 0; a < results.Count; a++)
  80.             {
  81.                 ResultBox.Items.Add(results[a].ToString());
  82.                
  83.             }
  84.                 if (results.Count == 2)
  85.                 {
  86.                     ResultBox.Items.Clear();
  87.                     ResultBox.Items.Add(NumberInput.ToString() + " is a prime number");
  88.                 }
  89.                 Calc.Text = "";
  90.  
  91.           }
  92.  
  93.         }
  94.  
  95.         private void Form1_Load(object sender, EventArgs e)
  96.         {
  97.  
  98.         }
  99.     }
  100.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement