Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FORM1
- 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 WindowsFormsApp1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void ex_Click(object sender, EventArgs e)
- {
- Form2 secondForm = new Form2();
- secondForm.Show();
- }
- }
- }
- FORM2
- 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 WindowsFormsApp1
- {
- public partial class Form2 : Form
- {
- int[] nums = new int[17];
- public Form2()
- {
- InitializeComponent();
- }
- private void Form2_Load(object sender, EventArgs e)
- {
- int p;
- int contador = 1;
- Random rnd = new Random();
- for (int i = 1; i <= 16; i++)
- {
- string name = "" + contador;
- TextBox text = new TextBox
- {
- Name = name,
- };
- p = rnd.Next(1, 999);
- nums[i] = p;
- text.Text = "" + p;
- if (i <= 4) text.Location = new System.Drawing.Point(i * 50, 50);
- else if (i > 4 && i <= 8) text.Location = new System.Drawing.Point((i - 4) * 50, 100);
- else if (i > 8 && i <= 12) text.Location = new System.Drawing.Point((i - 8) * 50, 150);
- else text.Location = new System.Drawing.Point((i - 12) * 50, 200);
- Controls.Add(text);
- contador++;
- }
- }
- private void button17_Click(object sender, EventArgs e)
- {
- int x;
- int soma = 0;
- int ini;
- int tot = 0;
- for (int i = 0; i <= 16; i++)
- {
- ini = nums[i];
- while (nums[i] != 0)
- {
- x = nums[i] % 10;
- soma = soma + (x * x * x);
- nums[i] = nums[i] / 10;
- }
- if (soma == ini)
- {
- MessageBox.Show(ini.ToString());
- tot++;
- }
- soma = 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment