若干個人排成一隊領取蘋果,第一個人領取一個,後面的每一個人領取的是前面蘋果數的兩倍兩倍再加上3個,請問第n個人的領了幾個蘋果。
static int apple (int n) {
int k;
if (n == 1) k = 1;
else k = 2 * apple(n - 1) + 3;
return(k);
}
static void Main(string[] args)
{
int a, k;
Console.WriteLine("請輸入領取蘋果的人數: ");
k = Convert.ToInt16(Console.ReadLine());
a = apple(k);
Console.WriteLine(a);
Console.ReadKey();
}
}