能同时被两个或者三个整数整除的数值
using System;using System.Windows.Forms;namespace A4{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void calculateButton1_Click(object sender, EventArgs e) { outputBox1.Text = ""; GetNum_1(); CalculateDivisor_1(); } private void calculateButton2_Click(object sender, EventArgs e) { outputBox2.Text = ""; GetNum_2(); CalculateDivisor_2(); } private int startNum; private int endNum; private int firstNum; private int secondNum; private int thirdNum; private void GetNum_1() { startNum = int.Parse(startNumBox1.Text); endNum = int.Parse(endNumBox1.Text); firstNum = int.Parse(firstNumBox1.Text); secondNum = int.Parse(secondNumBox1.Text); } private void GetNum_2() { startNum = int.Parse(startNumBox2.Text); endNum = int.Parse(endNumBox2.Text); firstNum = int.Parse(firstNumBox2.Text); secondNum = int.Parse(secondNumBox2.Text); thirdNum = int.Parse(thirdNumBox2.Text); } private void CalculateDivisor_1() { int nextLine = 0; outputBox1.Text = "在" startNum "和" endNum "之间能被" firstNum "和" secondNum "整除的数有:" Environment.NewLine; for (int i = startNum; i <= endNum; i ) { if (i % firstNum == 0 && i % secondNum == 0) { outputBox1.Text = (i "\t"); nextLine ; }if (nextLine == 4) { outputBox1.Text = Environment.NewLine; nextLine = 0; } } } private void CalculateDivisor_2() { int nextLine = 0; outputBox2.Text = "在" startNum "和" endNum "两个数之间能被" firstNum "和" secondNum "以及" thirdNum "整除的数有:" Environment.NewLine; for (int i = startNum; i <= endNum; i ) { if (i % firstNum == 0 && i % secondNum == 0 && i % thirdNum == 0) { outputBox2.Text = (i "\t"); nextLine ; }if (nextLine == 4) { outputBox2.Text = Environment.NewLine; nextLine = 0; } } } private void startNumBox1_TextChanged(object sender, EventArgs e) { } private void label7_Click(object sender, EventArgs e) { } private void groupBox3_Enter(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { this.Close(); } private void endbutton2_Click(object sender, EventArgs e) { this.Close(); } }}
评论