using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//有5个人坐在一起,问第5个人多少岁?他说比第4个人大2岁,问第4个人岁数,他说比第3个人大2岁,问第3个人,
//又说比第2人大两岁,问第2个人,说比第一个人大2岁,最后问第一个人,他说是10岁,请问第5个人多大.
namespace ans3
{
class Program
{
static void Main(string[] args)
{
int n = 5;
int age = Fun(n);
Console.WriteLine("第5个人{0}岁",age);
}
static int Fun(int n)
{
if(1==n)
return 10;
else
return Fun(n-1)+2;
}
}
}
c#编程:有5个人坐在一起,问第5个人多少岁的问题
最新推荐文章于 2024-01-25 16:06:44 发布