There are several small programs for the interview:
1. There is a series of numbers:,..., please nth? (Use two methods to obtain the nth bit and query the number of any bit)
// Fibonacci count
Private static List <long> GetNum (long n)
{
Long a = 1, B = 1, num = 0;
List <long> resultArry = new List <long> ();
Try
{
For (int I = 0; I <n; I ++)
{
Num = a + B;
A = B;
B = num;
ResultArry. Add (num );
}
}
Catch (Exception ex)
{
Throw new Exception (ex. Message );
}
Return resultArry;
}
static long i = 0, j = 1, result = 0;
static List<long> resultArry = new List<long>();
private static long ReturnNum(long n)
{
if (n <= 2)
{
result = i + j;
}
else
{
result = ReturnNum(n - 1) + ReturnNum(n - 2);
}
if (!resultArry.Contains(result))
{
resultArry.Add(result);
}
return result;
}
Static void Main (string [] args)
{
// Method 1:
List <long> resultArry = GetNum (10 );
Foreach (long result in resultArry)
{
Console. Write (result + ",");
}
// Method 2
// ReturnNum (10 );
// ResultArry. Insert (0, 1 );
// Foreach (long result in resultArry)
//{
// Console. Write (result + ",");
//}
Console. Read ();
}