编写一个求给定数值范围内的幸运数及其个数的程序。
所谓幸运数是指前两位数字之和等于后两位数字之和的四位正整数。例如2103,2+1=0+3,就是一个幸运数。首先在文本框1和文本框2中分别输入要求的幸运数的初值和终值,然后...
所谓幸运数是指前两位数字之和等于后两位数字之和的四位正整数。例如2103,2+1=0+3,就是一个幸运数。首先在文本框1和文本框2中分别输入要求的幸运数的初值和终值,然后单击“求幸运数”按钮,则求出给定范围内的所有幸运数并在列表框中显示结果,在文本框3中显示幸运数的个数;单击“清除”按钮,则将3个文本框及列表框清空,焦点置于文本框1上;在程序中应定义一个判断某数是否为幸运数的函数过程。
展开
2个回答
2013-07-06
展开全部
Private Function isxys(a) As Boolean
If a < 1000 Or a > 9999 Then
isxys = False
Else
t1 = Int(a / 1000) '取千位数
t2 = Int((a - t1 * 1000) / 100)
t3 = Int((a - t1 * 1000 - t2 * 100) / 10)
t4 = a - t1 * 1000 - t2 * 100 - t3 * 10
If t1 + t2 = t3 + t4 Then
isxys = True
Else
isxys = False
End If
End If
End Function
Private Sub Command1_Click()
s = 0
For i = Val(Text1.Text) To Val(Text2.Text)
If isxys(i) Then
List1.AddItem i
s = s + 1
End If
Next
Text3.Text = s
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
List1.Clear
Text1.SetFocus
End Sub
vb6.0代码
If a < 1000 Or a > 9999 Then
isxys = False
Else
t1 = Int(a / 1000) '取千位数
t2 = Int((a - t1 * 1000) / 100)
t3 = Int((a - t1 * 1000 - t2 * 100) / 10)
t4 = a - t1 * 1000 - t2 * 100 - t3 * 10
If t1 + t2 = t3 + t4 Then
isxys = True
Else
isxys = False
End If
End If
End Function
Private Sub Command1_Click()
s = 0
For i = Val(Text1.Text) To Val(Text2.Text)
If isxys(i) Then
List1.AddItem i
s = s + 1
End If
Next
Text3.Text = s
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
List1.Clear
Text1.SetFocus
End Sub
vb6.0代码
2013-07-06
展开全部
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int i;
int a, b, c, d;
int sum = 0;
for (i = Convert.ToInt32(textBox1.Text); i < Convert.ToInt32(textBox2.Text); i++)
{
a = i/1000;
b =i/100%10;
c =i/10%10;
d = i % 10;
if ((a + b) == ( c + d))
{
listView1.Items.Add(i.ToString());
sum++;
}
}
textBox3.Text = sum.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
textBox3.Text = "";
textBox1.Text = "";
textBox2.Text = "";
textBox1.Focus();
listView1.Items.Clear();
}
}
以上为c#程序代码
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int i;
int a, b, c, d;
int sum = 0;
for (i = Convert.ToInt32(textBox1.Text); i < Convert.ToInt32(textBox2.Text); i++)
{
a = i/1000;
b =i/100%10;
c =i/10%10;
d = i % 10;
if ((a + b) == ( c + d))
{
listView1.Items.Add(i.ToString());
sum++;
}
}
textBox3.Text = sum.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
textBox3.Text = "";
textBox1.Text = "";
textBox2.Text = "";
textBox1.Focus();
listView1.Items.Clear();
}
}
以上为c#程序代码
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询