1.a=10;b=15 在不使用第三个变量的情况下交换a,b的值:
a=a+b;
b=a-b;
a=a-b;
2.声明一个100大小的数组 随机插入1-100之间的数,不能重复
int[] intArr = new int[100];
ArrayList myList = new ArrayList();
Random rnd = new Random();
while (myList.Count < 100)
{
int num = rnd.Next(1, 101);
if (!myList.Contains(num))
myList.Add(num);
}
for (int i = 0; i <100; i++)
{
intArr[i] = (int)myList[i];
Console.Write("{0} ", intArr[i]);
Console.WriteLine();
}
3.asp.net(c#)遍历页面中的TextBox对象,并赋值为string.Empty,
for (int i = 0; i < Controls.Count; i++)
{
if (Controls[i] is TextBox)
{
((TextBox)Controls[i]).Text = string.Empty;
}
}
4。冒泡排序
int i,j,temp;
for(j=0;j<=9;j++)
{
for (i=0;i<10-j;i++)
{
if (a[i]>a[i+1])
{ temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
}
}
}
5。1、1、2、3、5、8。。。。。求第30个数是什么,用递归
public class MainClass
{
public static void Main()
{
Console.WriteLine(Foo(30));
}
public static int Foo(int i)
{
if (i <= 0)
return 0;
else if(i > 0 && i <= 2)
return 1;
else return Foo(i -1) + Foo(i - 2);
}
}
[@more@]来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9664444/viewspace-966475/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/9664444/viewspace-966475/