.net 面试算法题
1.请编程遍历页面上所有TextBox控件并给它赋值为string.Empty
foreach (System.Windows.Forms.Control control in this.Controls)
{
if (control is System.Windows.Forms.TextBox)
{
System.Windows.Forms.TextBox tb = (System.Windows.Forms.TextBox)control;
tb.Text = String.Empty;
}
}
2. 一列数的规则如下: 1、1、2、3、5、8、13、21、34...... 求第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);
}
}
3.经典排序—冒泡排序法
public static void bubble_sort(int[] x)
{
for (int i = 0; i < x.Length; i++)
{
for (int j = i; j < x.Length; j++)
{
if (x[i] < x[j]) //从大到小排序
{
int temp;
temp = x[i];
x[i] = x[j];
x[j] = temp;
}
}
}
}
4.写出一条Sql语句: 取出表A中第31到第40记录(SQLServer, 以自动增长的ID作为主键, 注意:ID可能不是连续的。)
select top 10 * from A where id not in (select top 30 id from A)
select top 10 * from A where id 〉 (select max(id) from (select top 30 id from A )as A)

浙公网安备 33010602011771号