父母難為,問個國中數學題....我和朋友想了兩個晚上

gary1587 wrote:
這個題目拿來當作是C語言的練習題我覺得倒是蠻好用的~~
可以用到陣列、條件判斷~
應該很好寫出來吧~


嗯嗯~~~的確不難...我也寫出來了...
也證實了...答案是138...
完全平方數的部分的確是空的!

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication18
{
public partial class Form1 : Form
{
CheckBox[] arbHole = new CheckBox[150+1];
bool[] abHole = new bool[150+1];
Point arbLocation = new Point(12, -8);
Button button1 = new Button();

public Form1()
{
InitializeComponent();

for (int iCount = 1; iCount < abHole.Length; iCount++)
{
arbHole[iCount] = new CheckBox();
arbHole[iCount].Text = "";
arbHole[iCount].Size = new Size(14,13);

if (iCount % 10 == 1)
{
arbLocation.X = 12;
arbLocation.Y += 20;
}
else
{
arbLocation.X += 20;
}

arbHole[iCount].Location = arbLocation;

this.Controls.Add(arbHole[iCount]);
}

button1.Location = new System.Drawing.Point(67, 317);
button1.Name = "button1";
button1.Size = new System.Drawing.Size(75, 23);
button1.TabIndex = 1;
button1.Text = "button1";
button1.UseVisualStyleBackColor = true;
button1.Click += new System.EventHandler(this.button1_Click);
this.Controls.Add(button1);
}

private void button1_Click(object sender, EventArgs e)
{
int iCount = 1, iCountMultiple = 1, iValue = 0;

for (iCount = 1; iCount < arbHole.Length; iCount++)
{
abHole[iCount] = true;
arbHole[iCount].Checked = true;
}

for (iCount = 1; iCount < arbHole.Length; iCount++)
{
for (iCountMultiple = 1; iCount * iCountMultiple < arbHole.Length; iCountMultiple++)
{
abHole[iCount * iCountMultiple] = !abHole[iCount * iCountMultiple];
arbHole[iCount * iCountMultiple].Checked = !arbHole[iCount * iCountMultiple].Checked;
}
}

for (iCount = 1; iCount < arbHole.Length; iCount++)
{
if (abHole[iCount])
iValue++;
}

button1.Text = iValue.ToString();
}
}
}
文章分享
評分
評分
複製連結

今日熱門文章 網友點擊推薦!