C#编程 (急求)

来源:百度知道 编辑:UC知道 时间:2024/07/11 19:32:19
一列数的规则如下:1、1、2、3、5、8、13、21、34......。编写一个控制台应用,求第30位数是多少。(要求使用递归算法实现)
设计一个描述坐标点的CPoint类,该类实现以下功能:其私有变量x和y代表一个点的x,y坐标值。利用构造函数传递参数,并设其默认参数值为60和75,利用公有成员方法display()输出这一默认值;利用公有成员方法setpoint()将坐标值修改为(80, 150),并利用成员方法输出修改后的坐标值。 这个怎么搞定?

public static void Main(string[] args){
Console.WriteLine(f(30));
}

public static int f(int n){
if(n == 1 || n == 2) {
return 1;
} else {
return f(n - 1) + f(n - 2);
}
}
}
斐波那契数列,用递归方法求第n+1项的值。

递推关键试:f(n)= {f(n-1)+ f(n-2) if n>1
0 if n =0
1 if n=1

一楼的回答很正确

class CPoint
{
int x = 60;
in y = 75;

public CPoint(){}
public CPoint(int _x, int _y)
{
this.x = _x;
this.y = _y;
}

public void display()
{
Console.WriteLine("x={0}, y={1}", this.x, this.y);
}

public void setpoint(int _x, int _y}
{
this.x = _x;
this.y = _y;
}
}

使用:
CPoint c = new CPoint();
c.display();