Nerviie

C#

Oct 29th, 2019
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.73 KB | None | 0 0
  1. FORM1
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11.  
  12. namespace WindowsFormsApp1
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         public Form1()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.  
  21.         private void Form1_Load(object sender, EventArgs e)
  22.         {
  23.  
  24.         }
  25.  
  26.         private void ex_Click(object sender, EventArgs e)
  27.         {
  28.             Form2 secondForm = new Form2();
  29.             secondForm.Show();
  30.         }
  31.     }
  32. }
  33.  
  34.  
  35.  
  36.  
  37. FORM2
  38. using System;
  39. using System.Collections.Generic;
  40. using System.ComponentModel;
  41. using System.Data;
  42. using System.Drawing;
  43. using System.Linq;
  44. using System.Text;
  45. using System.Threading.Tasks;
  46. using System.Windows.Forms;
  47.  
  48. namespace WindowsFormsApp1
  49. {
  50.     public partial class Form2 : Form
  51.     {
  52.         int[] nums = new int[17];
  53.         public Form2()
  54.         {
  55.             InitializeComponent();
  56.         }
  57.        
  58.             private void Form2_Load(object sender, EventArgs e)
  59.             {
  60.             int p;
  61.             int contador = 1;
  62.             Random rnd = new Random();
  63.             for (int i = 1; i <= 16; i++)
  64.             {
  65.                 string name = "" + contador;
  66.                 TextBox text = new TextBox
  67.                 {
  68.                     Name = name,
  69.                  };
  70.                 p = rnd.Next(1, 999);
  71.                 nums[i] = p;
  72.                 text.Text = "" + p;
  73.                 if (i <= 4) text.Location = new System.Drawing.Point(i * 50, 50);
  74.                 else if (i > 4 && i <= 8) text.Location = new System.Drawing.Point((i - 4) * 50, 100);
  75.                 else if (i > 8 && i <= 12) text.Location = new System.Drawing.Point((i - 8) * 50, 150);
  76.                 else text.Location = new System.Drawing.Point((i - 12) * 50, 200);
  77.                 Controls.Add(text);
  78.                 contador++;
  79.  
  80.             }
  81.            
  82.  
  83.         }  
  84.  
  85.         private void button17_Click(object sender, EventArgs e)
  86.         {
  87.             int x;
  88.             int soma = 0;
  89.             int ini;
  90.             int tot = 0;
  91.             for (int i = 0; i <= 16; i++)
  92.             {
  93.                 ini = nums[i];
  94.                 while (nums[i] != 0)
  95.                 {
  96.                     x = nums[i] % 10;
  97.                     soma = soma + (x * x * x);
  98.                     nums[i] = nums[i] / 10;
  99.                 }
  100.  
  101.                 if (soma == ini)
  102.                 {
  103.                     MessageBox.Show(ini.ToString());
  104.                     tot++;
  105.                 }
  106.                 soma = 0;
  107.             }
  108.             }
  109.            
  110.        
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment