Pushok

разложение на множители

Mar 7th, 2011
669
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.25 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 Разложение
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         public static int len = 0;
  15.         public static int lenf = 0;
  16.         public Form1()
  17.         {
  18.             InitializeComponent();
  19.             len = listBox1.Height;
  20.             lenf = this.Height;
  21.             textBox1.Click += new EventHandler(tb_eventClick);
  22.         }
  23.         private void tb_eventClick(object snd, EventArgs a)
  24.         {
  25.             textBox1.Text = "";
  26.         }
  27.  
  28.         private void button1_Click(object sender, EventArgs e)
  29.         {
  30.             try
  31.             {
  32.                 listBox1.Items.Clear();
  33.                 listBox1.Height = len;
  34.                 this.Height = len + 10;
  35.                 decimal a = Convert.ToDecimal(textBox1.Text);
  36.                 decimal[] ard = new decimal[1000];
  37.                 decimal[] dl = new decimal[1000];
  38.                 ard[0] = a;
  39.                 for (decimal i = 2, ct = 1, pt = 0; ; )
  40.                 {
  41.                     if (a % i == 0)
  42.                     {
  43.                         ard[checked((int)ct++)] = a /= i;
  44.                         dl[checked((int)pt++)] = i;
  45.                     }
  46.                     else i++;
  47.                     if (a == 1)
  48.                     {
  49.                         for (decimal g = 0; g < ct - 1; g++)
  50.                             listBox1.Items.Add(ard[checked((int)g)].ToString() + "," + dl[checked((int)g)].ToString());
  51.                         listBox1.Items.Add(a.ToString());
  52.                         break;
  53.                     }
  54.                 }
  55.                 listBox1.Height += 13 * listBox1.Items.Count;
  56.                 this.Height += listBox1.Height + 40;
  57.             }
  58.             catch (OverflowException)
  59.             {
  60.                 MessageBox.Show(this, "Слишком большое число", "Ошибка", MessageBoxButtons.OK);
  61.             }
  62.             catch (Exception)
  63.             {
  64.                 this.Height = lenf;
  65.                 MessageBox.Show(this, "...", "Ошибка", MessageBoxButtons.OK);
  66.             }
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment