第三章
循环结构课后作(二)
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
作业四:查找数组中的最大数
![](https://s1.51cto.com/attachment/201006/201006011275379192781.png)
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
public
partial
class
_Default
: System.Web.UI.
Page
{
protected
void
Page_Load(
object
sender,
EventArgs
e)
{
}
public
partial
class
_default
: System.Web.UI.
Page
//
声明属性
{
}
protected
void
Button1_Click(
object
sender,
EventArgs
e)
{
Label1.Text =
""
;
//
清空控件中的值
int
[] arraylist = { 33, 55, 55, 66, 88, 77, 44, 99, 59, 852 };
//
定义数组中的值
foreach
(
int
k
in
arraylist)
//
循环
{
Label1.Text += k +
" "
;
}
}
protected
void
Button2_Click(
object
sender,
EventArgs
e)
{
int
[] arraylist = { 33, 55, 55, 66, 88, 77, 44, 99, 59, 852 };
int
max = 0;
//
定义最大值
for
(
int
i = 0; i < arraylist.Length; i++)
//
定义小于数组的长度的值
{
if
(max < arraylist[i])
{
max = arraylist[i];
Label2.Text =
Convert
.ToString(max);
}
}
}
}
![](https://s1.51cto.com/attachment/201006/201006011275379243375.png)
![](https://s1.51cto.com/attachment/201006/201006011275379253640.png)
作业五: 显示购物清单及总价格页面效果图
![](https://s1.51cto.com/attachment/201006/201006011275379308484.png)
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
public
partial
class
_Default
: System.Web.UI.
Page
{
protected
void
Page_Load(
object
sender,
EventArgs
e)
{
}
protected
void
Button1_Click(
object
sender,
EventArgs
e)
{
Label1.Text =
""
;
string
[] wupin = {
"
上衣"
,
"
裙子"
,
"
香水"
,
"
挎包"
,
"
饮料"
,
"
发夹"
,
"
如何成为一个准职业人"
};
double
[] jiage = { 485, 266.8, 594, 78, 3.5, 10.8, 18.6 };
double
sum = 0;
for
(
int
i = 0; i < wupin.Length; i++)
{
sum += jiage[i];
//
每次执行循环时,总是加上它的上一个值;
Label1.Text += wupin[i] +
":"
+ jiage[i] +
"<br>"
;
Label2.Text = sum.ToString();
}
}
}
![](https://s1.51cto.com/attachment/201006/201006011275379348953.png)
转载于:https://blog.51cto.com/caohongjiang/324860