经文的兔子生兔子难点

By admin in 4858.com on 2019年5月3日

掌故难点:有壹对兔子,从诞生后第7个月起各样月都生一对兔子,小兔子长到第八个月后各种月又生一对兔子,假如兔子都不死,问各样月的兔子总量为多少?

一、概念

C# 函数,

函数:能够独立完毕某项成效的模块。

函数4要素:输入、输出、函数体、函数名

函数定义:
(static/public) 重返类型 函数名(参数类型 参数名,参数类型 参数名)
{
函数体
}

函数的调用:
回到变量类型 变量名 = 函数(实参值)

案例:输入2个数求阶乘(写成函数调用)
/// <summary>
/// 求阶乘
/// </summary>
public void Jie()
{
Console.Write(“请输入a=”);
int a = int.Parse(Console.ReadLine());
int jie = 1;
for (int i = 1; i <= a; i++)
{
jie *= i;
}
Console.Write(“阶乘结果是:” + jie);
Console.ReadLine();
}
static void Main(string[] args)
{
Program hanshu = new Program();
//首先须求将这一个类初阶化一下
hanshu.Jie();

可写成:带传值的
/// <summary>
/// 求阶乘
/// </summary>
public void Jie(int a)
{
int jie = 1;
for (int i = 1; i <= a; i++)
{
jie *= i;
}
Console.Write(“阶乘结果是:” + jie);
Console.ReadLine();
}
static void Main(string[] args)
{
Program hanshu = new Program();
//首先须要将以此类开头化一下
Console.Write(“请输入a=”);
int a = int.Parse(Console.ReadLine());
hanshu.Jie(a);

能够写成传值加重临值的:
/// <summary>
/// 求阶乘
/// </summary>
public int Jie(int a)
{
int jie = 1;
for (int i = 1; i <= a; i++)
{
jie *= i;
}
return jie;
}
static void Main(string[] args)
{
Program hanshu = new Program();
//首先须求将以此类起始化一下
Console.Write(“请输入a=”);
int a = int.Parse(Console.ReadLine());

Console.Write(“阶乘结果是:” + hanshu.Jie(a));
Console.ReadLine();

可以写成不传值但是带重临值的:
/// <summary>
/// 求阶乘
/// </summary>
public int Jie()
{
Console.Write(“请输入a=”);
int a = int.Parse(Console.ReadLine());
int jie = 1;
for (int i = 1; i <= a; i++)
{
jie *= i;
}
return jie;
}
static void Main(string[] args)
{
Program hanshu = new Program();
//首先须要将以此类开端化一下
Console.Write(“阶乘结果是:” + hanshu.Jie());
Console.ReadLine();

例:写3个回来最大值的函数。调用。
/// <summary>
/// 八个数十分大小重返大的
/// </summary>
/// <param name=”a”></param>
/// <param name=”b”></param>
/// <returns></returns>
public int Max(int a, int b)
{
if (a > b)
{
return a;
}
else
{
return b;
}
}
static void Main(string[] args)
{
Program hanshu = new Program();
//首先必要将这一个类初步化一下
Console.WriteLine(hanshu.Max(hanshu.Max(a, b), c));
//函数不仅能够屡屡采取,还足以嵌套使用

细化

namespace 函数
{
class Program
{
格式一:无参无返
<summary>
累加求和,无需参数,未有再次回到值
</summary>
public void LeiJia()
{
累加求和
Console.Write(“请输入三个正整数:”);
int a = int.Parse(Console.ReadLine());
int sum = 0;
for (int i = 1; i <= a; i++)
{
sum += i;
}
Console.WriteLine(sum);
Console.ReadLine();
}

 

格式二:无参有返
public int LeiJia1()
{
累加求和
Console.Write(“请输入二个正整数:”);
int a = int.Parse(Console.ReadLine());
int sum = 0;
for (int i = 1; i <= a; i++)
{
sum += i;
}

return sum;
}

 

格式叁:有参有返
public int LeiJia2(int a)
{
累加求和
int sum = 0;
for (int i = 1; i <= a; i++)
{
sum += i;
}
return sum;
}

格式四:有参无返
public void LeiJia3(int a)
{
累加求和
int sum = 0;
for (int i = 1; i <= a; i++)
{
sum += i;
}
Console.WriteLine(sum);
Console.ReadLine();
}

有参数表示在函数体中不须求再去接受
有重返值表示,小编在下文中还亟需选取这些结果
在调用函数的时候需求定义贰个一样数据类型的变量接收

函数,异常的大小重回大的
public double Max(double a, double b)
{
if (a > b)
{
return a;
}
else//a<=b
{
return b;
}
}
函数能够嵌套使用,不过函数不得以嵌套写

 

public void you()//邮箱,无参无返
{
Console.Write(“请输入邮箱:”);
string yx = Console.ReadLine();
if(yx.Contains (“@”))
{
int a=yx.IndexOf (“@”);
int b=yx.LastIndexOf (“@”);
if (a == b)
{
if(!yx.StartsWith (“@”))
{
string c = yx.Substring(a);
if(c.Contains (“.”))
{
string d=yx.Substring (a-1,1);
string e = yx.Substring(a, 1);
if(d!=”.”&&e!=”.”)
{
if(!yx.EndsWith (“.”))
{
Console.WriteLine(“您输入的信箱格式正确”);
}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console.WriteLine(“邮箱输入错误”);
}

}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console .WriteLine (“邮箱输入错误”);
}
Console.ReadLine();
}

 

 

public string you二() //无参有返
{
Console.Write(“请输入邮箱:”);
string yx = Console.ReadLine();
if (yx.Contains(“@”))
{
int a = yx.IndexOf(“@”);
int b = yx.LastIndexOf(“@”);
if (a == b)
{
if (!yx.StartsWith(“@”))
{
string c = yx.Substring(a);
if (c.Contains(“.”))
{
string d = yx.Substring(a – 1, 1);
string e = yx.Substring(a, 1);
if (d != “.” && e != “.”)
{
if (!yx.EndsWith(“.”))
{
Console.WriteLine(“您输入的邮箱格式正确”);
}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console.WriteLine(“邮箱输入错误”);
}

}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console.WriteLine(“邮箱输入错误”);
}

return yx;
}

有参有返
public string you3(string yx)
{
if (yx.Contains(“@”))
{
int a = yx.IndexOf(“@”);
int b = yx.LastIndexOf(“@”);
if (a == b)
{
if (!yx.StartsWith(“@”))
{
string c = yx.Substring(a);
if (c.Contains(“.”))
{
string d = yx.Substring(a – 1, 1);
string e = yx.Substring(a, 1);
if (d != “.” && e != “.”)
{
if (!yx.EndsWith(“.”))
{
Console.WriteLine(“您输入的邮箱格式准确”);
}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console.WriteLine(“邮箱输入错误”);
}

}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console.WriteLine(“邮箱输入错误”);
}
return yx;
}

有参无返

public void you4(string yx)
{
经文的兔子生兔子难点。if (yx.Contains(“@”))
{
int a = yx.IndexOf(“@”);
int b = yx.LastIndexOf(“@”);
if (a == b)
{
if (!yx.StartsWith(“@”))
{
string c = yx.Substring(a);
if (c.Contains(“.”))
{
string d = yx.Substring(a – 1, 1);
string e = yx.Substring(a, 1);
if (d != “.” && e != “.”)
{
if (!yx.EndsWith(“.”))
{
Console.WriteLine(“您输入的邮箱格式正确”);
}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console.WriteLine(“邮箱输入错误”);
}

}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console.WriteLine(“邮箱输入错误”);
}
Console.ReadLine();
}

加10分,给数组中的
public double[] JiaFen(double[] score)
{
for (int i = 0; i < score.Length; i++)
{
score[i] += 10;
}
return score;
}

public int renzong = 0;
public int dianzong = 0;

public string Cai()
{
Console.Write(“请输入您出如何拳(剪刀、石头、布):”);
string shu = Console.ReadLine();

if (shu == “剪刀” || shu == “石头” || shu == “布”)
{
int ren = 0;
switch (shu)
{
case “剪刀”:
ren = 1;
break;
case “石头”:
ren = 2;
break;
case “布”:
ren = 3;
break;
}
Random ran = new Random();
int dian = ran.Next(1, 4);
switch (dian)
{
case 1:
Console.WriteLine(“计算机出剪刀”);
break;
case 2:
Console.WriteLine(“Computer出石头”);
break;
case 3:
Console.WriteLine(“Computer出布”);
break;
}
int jie = ren – dian;
if (jie == 0)
{
return “本轮平局!”;
}
else if (jie == 1 || jie == -2)
{
return “本轮胜出!”;
}
else
{
return “本轮失利!”;
}
}
else
{
return “输入有误!”;
}
}
public void tizhong()
{
Console.Write(“请输入性别”);
string s = Console.ReadLine();
Console.Write(“请输入体重”);
double t = double.Parse(Console.ReadLine());
Console.Write(“请输入身高”);
double g = double.Parse(Console.ReadLine());
if (s == “男”)
{
double n = t – g + 100;
if (n > 3 && n <= -3)
{
Console.WriteLine(“您是正经体重”);
}
else if (n > 3)
{
Console.WriteLine(“您的体重偏胖”);
}
else
{
Console.WriteLine(“您的体重偏瘦”);
}
}
else if (s == “女”)
{
double n = t – g + 110;
if (n > 3 && n <= -3)
{
Console.WriteLine(“您是正经体重”);
}
else if (n > 3)
{
Console.WriteLine(“您的体重偏胖”);
}
else
{
Console.WriteLine(“您的体重偏瘦”);
}
}
else
{
Console.WriteLine(“您的输入有误”);
}
Console.ReadLine();
}

 

static void Main(string[] args)
{
务求:写三个函数,计算体重是不是正规
函数需求四个输入值,分别为性别、体重kg、身高cm
男:身高-100=体重±3kg
女:身高-110=体重±3kg
Console.Write(“请输入性别”);
string s = Console.ReadLine();
Console.Write(“请输入体重”);
double t = double.Parse(Console.ReadLine());
Console.Write(“请输入身高”);
double g = double.Parse(Console.ReadLine());
if (s == “男”)
{
double n = t – g + 100;
if (n > 3 && n <= -3)
{
Console.WriteLine(“您是专门的工作体重”);
}
else if (n > 3)
{
Console.WriteLine(“您的体重偏胖”);
}
else
{
Console.WriteLine(“您的体重偏瘦”);
}
}
else if (s == “女”)
{
double n = t – g + 110;
if (n > 3 && n <= -3)
{
Console.WriteLine(“您是标准体重”);
}
else if (n > 3)
{
Console.WriteLine(“您的体重偏胖”);
}
else
{
Console.WriteLine(“您的体重偏瘦”);
}
}
else
{
Console.WriteLine(“您的输入有误”);
}
Console.ReadLine();
Program hanshu = new Program();
hanshu.tizhong();

 

首先对其它市的类进行开始化
Program hanshu = new Program();
hanshu.LeiJia();
int sum = hanshu.LeiJia1();
在那个数值上再加13分
sum += 10;

int sum= hanshu.LeiJia2(5);

Console.WriteLine(sum);
Console.ReadLine();

hanshu.LeiJia3(5);

Console.Write(“请输入a=”);
double a = double.Parse(Console.ReadLine());
Console.Write(“请输入b=”);
double b = double.Parse(Console.ReadLine());
Console.Write(“请输入c=”);
double c = double.Parse(Console.ReadLine());
double max = hanshu.Max( hanshu.Max(a,b),c);

Console.WriteLine(max);
Console.ReadLine();

输入邮箱账号,剖断是或不是格式准确
Program han = new Program();
han.you();

string yx = han.you2( );
Console.WriteLine(yx);
Console.ReadLine();

 

Console.WriteLine(“请输入邮箱地址”);
string yx = han.you3(Console .ReadLine ());
Console.WriteLine(yx);
Console.ReadLine();

Console.WriteLine(“请输入邮箱地址”);
han.you4(Console .ReadLine ());

 

渴求输入班级人数,依据人口输入每种人的分数
是因为那么些班都是少数民族,所以都供给加13分
加11分的经过要求用到函数
Console.Write(“请输入班级人数:”);
int a = int.Parse(Console.ReadLine());
double [] score =new double [a];
for (int i = 0; i < a; i++)
{
Console.Write(“请输入第{0}个人的分数:”,i+一);
score[i] = double.Parse(Console.ReadLine());
}
Console.WriteLine(“全部学员分数输入落成,请按回车键继续!”);
Console.ReadLine();
初始化
Program hanshu = new Program();
score = hanshu.JiaFen(score);

foreach (double aa in score)
{
Console.WriteLine(aa);
}
Console.ReadLine();

 

猜拳:
人机迎阵
剪刀 1
石头 2
包袱 3
人输入:(剪刀、石头、布)
0 平局
1 赢了
-1 输了
-2 赢了
2 输了
Console.Write(“请输入您出什么拳(剪刀、石头、布):”);
string shu = Console.ReadLine();

if (shu == “剪刀” || shu == “石头” || shu == “布”)
{
int ren = 0;
switch (shu)
{
case “剪刀”:
ren = 1;
break;
case “石头”:
ren = 2;
break;
case “布”:
ren = 3;
break;
}
Random ran = new Random();
int dian = ran.Next(1, 4);
switch (dian)
{
case 1:
Console.WriteLine(“Computer出剪刀”);
break;
case 2:
Console.WriteLine(“Computer出石头”);
break;
case 3:
Console.WriteLine(“计算机出布”);
break;
}
int jie = ren – dian;
if (jie == 0)
{
Console.WriteLine(“本轮平局!”);
}
else if (jie == 1 || jie == -2)
{
Console.WriteLine(“本轮胜出!”);
}
else
{
Console.WriteLine(“本轮失败!”);
}
}
else
{
Console.WriteLine(“输入有误!”);
}

Console.ReadLine();

 

输入进程中若出错
for (int i = 1; i > 0; i++)
{
Console.Write(“请输入是要么不是!”);
string ss = Console.ReadLine();
if (ss == “是” || ss == “不是”)
{
break;
}
else
{
Console.WriteLine(“输入有误!请重新输入!”);
}
}
输入年月日,查看时间日期格式是或不是精确

for (int i = 1; i > 0; i++)
{
Console.Write(“请输入年份:”);
int year = int.Parse(Console.ReadLine());
if (year >= 0 && year <= 9999)
{
for (int a = 1; a > 0; a++)
{
Console.Write(“请输入月份:”);
int month = int.Parse(Console.ReadLine());
if (month >= 1 && month <= 12)
{
for (int b = 1; b > 0; b++)
{
Console.Write(“请输入日期:”);
int day = int.Parse(Console.ReadLine());
if (day >= 1 && day <= 31)
{
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8
|| month == 10 || month == 12)
{
Console.WriteLine(“您输入的日子格式正确,您输入的日子是:{0}年{一}月{贰}日”,
year, month, day);
break;
}
else
{
if (month == 4 || month == 6 || month == 9 || month == 11)
{
if (day == 31)
{
Console.WriteLine(“您输入的日期错误,请重新输入!”);
continue;
}
else
{
Console.WriteLine(“您输入的日期格式正确,您输入的日子是:{0}年{1}月{2}日”,
year, month, day);
break;
}
}
else
{
if (day <= 28)
{
Console.WriteLine(“您输入的日子格式正确,您输入的日期是:{0}年{一}月{二}日”,
year, month, day);
break;
}
else
{
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
{
if (day == 29)
{
Console.WriteLine(“您输入的日子格式精确,您输入的日期是:{0}年{一}月{2}日”,
year, month, day);
break;
}
else
{
Console.WriteLine(“您输入的日期错误,请重新输入!”);
continue;
}
}
else
{
Console.WriteLine(“您输入的日期错误,请重新输入!”);
continue;
}
}
}
}
}
else
{
Console.WriteLine(“您输入的日期错误,请重新输入!”);
continue;
}
}
a = -10;
}
else
{
Console.WriteLine(“您输入的月度错误,请重新输入!”);
continue;
}
}
}
else
{
Console.WriteLine(“您输入的年度错误,请重新输入!”);
continue;
}
i = -10;
}Console.ReadLine();

 

for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
if (j == 3)
{
break;//break跳出近期的巡回
}
Console.Write(“■”);

}
Console.WriteLine();
}

Console.ReadLine();

}
}
}

函数, 函数:能够独立完结某项成效的模块。
函数4因素:输入、输出、函数体、函数名 函数定义: (static/public)
再次回到类型 函数名(…

函数:能够单独完毕某项作用的模块。

思路:先求出各种月猛增的兔子,再用循环求和就能够算出当月总的兔子数。

函数体内吊用本函数自个儿,直到适合某壹标准不在继续调用。

函数肆因素:输入、输出、函数体、函数名

月份  新增兔子

 

函数定义:
(static/public) 再次来到类型 函数名(参数类型 参数名,参数类型 参数名)
{
函数体
}

1    1

二、应知足自家条件

函数的调用:
回去变量类型 变量名 = 函数(实参值)

2    0

(一)有频仍施行的进程(调用自个儿);

案例:输入1个数求阶乘(写成函数调用)
/// <summary>
/// 求阶乘
/// </summary>
public void Jie()
{
Console.Write(“请输入a=”);
int a = int.Parse(Console.ReadLine());
int jie = 1;
for (int i = 1; i <= a; i++)
{
jie *= i;
}
Console.Write(“阶乘结果是:” + jie);
Console.ReadLine();
}
static void Main(string[] args)
{
Program hanshu = new Program();
//首先必要将以此类初步化一下
hanshu.Jie();

3    1

(贰)有跳出反复实行进度的规格(函数出口)

可写成:带传值的
/// <summary>
/// 求阶乘
/// </summary>
public void Jie(int a)
{
int jie = 1;
for (int i = 1; i <= a; i++)
{
jie *= i;
}
Console.Write(“阶乘结果是:” + jie);
Console.ReadLine();
}
static void Main(string[] args)
{
Program hanshu = new Program();
//首先供给将以此类早先化一下
Console.Write(“请输入a=”);
int a = int.Parse(Console.ReadLine());
hanshu.Jie(a);

4    1

三、例子

能够写成传值加再次回到值的:
/// <summary>
/// 求阶乘
/// </summary>
public int Jie(int a)
{
int jie = 1;
for (int i = 1; i <= a; i++)
{
jie *= i;
}
return jie;
}
static void Main(string[] args)
{
Program hanshu = new Program();
//首先供给将那个类开端化一下
Console.Write(“请输入a=”);
int a = int.Parse(Console.ReadLine());

5    1 + 1

4858.com 1

Console.Write(“阶乘结果是:” + hanshu.Jie(a));
Console.ReadLine();

6    1 + 1 + 1

肆、注意事项

能够写成不传值不过带重回值的:
/// <summary>
/// 求阶乘
/// </summary>
public int Jie()
{
Console.Write(“请输入a=”);
int a = int.Parse(Console.ReadLine());
int jie = 1;
for (int i = 1; i <= a; i++)
{
jie *= i;
}
return jie;
}
static void Main(string[] args)
{
Program hanshu = new Program();
//首先要求将以此类发轫化一下
Console.Write(“阶乘结果是:” + hanshu.Jie());
Console.ReadLine();

七    (一 + 1 + 一)7月份猛增的兔子 + (一 + 1)四月份新扩张的兔子

一.递归中必供给存在一个循环往复停止的准绳。

例:写一个回来最大值的函数。调用。
/// <summary>
/// 七个数极大小重临大的
/// </summary>
/// <param name=”a”></param>
/// <param name=”b”></param>
/// <returns></returns>
public int Max(int a, int b)
{
if (a > b)
{
return a;
}
else
{
return b;
}
}
static void Main(string[] args)
{
Program hanshu = new Program();
//首先供给将那一个类先河化一下
Console.WriteLine(hanshu.Max(hanshu.Max(a, b), c));
//函数不仅能够屡屡行使,还足以嵌套使用

…    …

2.递归函数的历次调用都必要栈来积攒,要是次数太多的话轻易形成栈溢出。

细化

n    n – 四月份增加产量的兔子 + n – 十月份激增的兔子

4858.com 2

namespace 函数
{
class Program
{
格式壹:无参无返
<summary>
累加求和,无需参数,未有再次回到值
</summary>
public void LeiJia()
{
累加求和
Console.Write(“请输入三个正整数:”);
int a = int.Parse(Console.ReadLine());
int sum = 0;
for (int i = 1; i <= a; i++)
{
sum += i;
}
Console.WriteLine(sum);
Console.ReadLine();
}

解法大旨:各类月的新增添的兔子都在下本月以及未来的各种月生下一对新兔子,那对新兔子在下当月以及之后的各样月都会生下①对新兔子,以此原理循环。

例题:

 

    因而,只要后3个月有新扩充的兔子后,上一个月都会骤增和下个月新兔子数量同样的兔子,同时还会新添上前段日子兔子数量的新兔子。那多个数据相加就收获前段时期一共新增的兔子。

一批羊赶到个村子去卖,每过二个村丢失此前线总指挥部数的5/10零一头,过了柒个山村之后还剩四只,问最初赶出有些只羊

格式2:无参有返
public int LeiJia1()
{
累加求和
Console.Write(“请输入2个正整数:”);
int a = int.Parse(Console.ReadLine());
int sum = 0;
for (int i = 1; i <= a; i++)
{
sum += i;
}

用递归的不贰秘技求出每一种月猛增的兔子(自定义函数):

 class
Program

return sum;
}

        static int NewRabbitOfMonth(int n)
        {
            if(n == 1)
            {
                return 1;
            }
            else if(n == 2)
            {
                return 0;
            }
            else
            {
                return NewRabbitOfMonth(n – 1) + NewRabbitOfMonth(n –
2);
            }
        }

{
public int dgqiuyang(int cun)
{
int sum = 0;
if (cun == 7)
{
return 2;
}
sum = 2*(dgqiuyang(cun + 1) + 1);
return sum;
}

 

用循环求和的办法求出每一种月的兔子总量(主函数):

static
void Main(string[] args)
{

格式三:有参有返
public int LeiJia2(int a)
{
累加求和
int sum = 0;
for (int i = 1; i <= a; i++)
{
sum += i;
}
return sum;
}

        static void Main(string[] args)
        {
            Console.Write(“请输入第多少个月:”);
            int n = int.Parse(Console.ReadLine());
            int sumRabbitOfMonth = 0;
            for(int i =1; i <= n; i++)
            {
                sumRabbitOfMonth += NewRabbitOfMonth(i);
            }
            Console.Write(“第” + n + “个月共有” + sumRabbitOfMonth +
“对兔子”);
            Console.ReadLine();
        }

Program
hb = new Program();
double x
= hb.dgqiuyang(1);

格式4:有参无返
public void LeiJia3(int a)
{
累加求和
int sum = 0;
for (int i = 1; i <= a; i++)
{
sum += i;
}
Console.WriteLine(sum);
Console.ReadLine();
}

思考:

Console.Write(“递归求羊”+x);

有参数表示在函数体中无需再去接受
有重临值表示,小编在下文中还亟需选用那些结果
在调用函数的时候必要定义1个均等数据类型的变量接收

各种月猛增的兔子数量其实是二个斐波拉契数列:
1,0,1,1,2,3,5…

Console.ReadLine();

函数,相当大小重返大的
public double Max(double a, double b)
{
if (a > b)
{
return a;
}
else//a<=b
{
return b;
}
}
函数能够嵌套使用,可是函数无法嵌套写

种种月总的兔子数量也是1个斐波拉契数列:

}

 

1,1,2,3,5,8,13…

}
}

public void you()//邮箱,无参无返
{
Console.Write(“请输入邮箱:”);
string yx = Console.ReadLine();
if(yx.Contains (“@”))
{
int a=yx.IndexOf (“@”);
int b=yx.LastIndexOf (“@”);
if (a == b)
{
if(!yx.StartsWith (“@”))
{
string c = yx.Substring(a);
if(c.Contains (“.”))
{
string d=yx.Substring (a-1,1);
string e = yx.Substring(a, 1);
if(d!=”.”&&e!=”.”)
{
if(!yx.EndsWith (“.”))
{
Console.WriteLine(“您输入的信箱格式精确”);
}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console.WriteLine(“邮箱输入错误”);
}

上边个数列每一项减去地点个数据各个获得的新数列也是斐波拉契数列:

例题:

}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console .WriteLine (“邮箱输入错误”);
}
Console.ReadLine();
}

0,1,1,2,3,5,8…

 

 

结论:

//编写递归函数求 贰*4*6*……*(2n) 的结果
public int dgqiuyang(int cun)
{
int sum = 0;
if (cun == 7)
{
return 2;
}
sum = 2 * (dgqiuyang(cun + 1) + 1);
return sum;
}

 

1个斐波拉契数量的每壹项减去另三个斐波拉契数列的呼应每1项获得的新数列也是斐波拉契数列。(待验证)

static void Main(string[] args)

public string you二() //无参有返
{
Console.Write(“请输入邮箱:”);
string yx = Console.ReadLine();
if (yx.Contains(“@”))
{
int a = yx.IndexOf(“@”);
int b = yx.LastIndexOf(“@”);
if (a == b)
{
if (!yx.StartsWith(“@”))
{
string c = yx.Substring(a);
if (c.Contains(“.”))
{
string d = yx.Substring(a – 1, 1);
string e = yx.Substring(a, 1);
if (d != “.” && e != “.”)
{
if (!yx.EndsWith(“.”))
{
Console.WriteLine(“您输入的信箱格式正确”);
}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console.WriteLine(“邮箱输入错误”);
}

 

{
//Program jie= new Program();

}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console.WriteLine(“邮箱输入错误”);
}

//Console.Write(“请输入贰个值:”);
//int n =
int.Parse(Console.ReadLine());
//int b =
jie.jie(n);
//Console.Write(b);
//Console.ReadLine();

return yx;
}

//有雌雄一对兔子,每过2个月便可繁殖雌雄各壹的壹对小兔子。

有参有返
public string you3(string yx)
{
if (yx.Contains(“@”))
{
int a = yx.IndexOf(“@”);
int b = yx.LastIndexOf(“@”);
if (a == b)
{
if (!yx.StartsWith(“@”))
{
string c = yx.Substring(a);
if (c.Contains(“.”))
{
string d = yx.Substring(a – 1, 1);
string e = yx.Substring(a, 1);
if (d != “.” && e != “.”)
{
if (!yx.EndsWith(“.”))
{
Console.WriteLine(“您输入的邮箱格式准确”);
}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console.WriteLine(“邮箱输入错误”);
}

//问过n个月后共有多少对兔子?

}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console.WriteLine(“邮箱输入错误”);
}
return yx;
}

public int t(int z)
{
int sh = 0;
if (z == 1)
{
return 2;
}
sh = 2 * t(z – 1);
return sh;
}

有参无返

static void Main(string[] args)

public void you4(string yx)
{
if (yx.Contains(“@”))
{
int a = yx.IndexOf(“@”);
int b = yx.LastIndexOf(“@”);
if (a == b)
{
if (!yx.StartsWith(“@”))
{
string c = yx.Substring(a);
if (c.Contains(“.”))
{
string d = yx.Substring(a – 1, 1);
string e = yx.Substring(a, 1);
if (d != “.” && e != “.”)
{
if (!yx.EndsWith(“.”))
{
Console.WriteLine(“您输入的邮箱格式准确”);
}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console.WriteLine(“邮箱输入错误”);
}

{
//Program tt = new Program();
//Console.Write(“请输入月数:”);
//int m = int.Parse(Console.ReadLine());
//int y = tt.t(m);
//Console.Write(y);
//Console.ReadLine();

}
else
{
Console.WriteLine(“邮箱输入错误”);
}
}
else
{
Console.WriteLine(“邮箱输入错误”);
}
Console.ReadLine();
}

 

加十二分,给数组中的
public double[] JiaFen(double[] score)
{
for (int i = 0; i < score.Length; i++)
{
score[i] += 10;
}
return score;
}

//五个候选人选举班长:张叁,李4,王5,赵陆,冯七
//班级中共有十几个人,拾拾个人轮流投票
//只要不是一~5之内的正是作废
//最终要精晓何人的票数最多,当选班长

public int renzong = 0;
public int dianzong = 0;

 

public string Cai()
{
Console.Write(“请输入您出哪些拳(剪刀、石头、布):”);
string shu = Console.ReadLine();

enum Houxuanren : int
{
one = 1,
two,
three,
four,
five
}

if (shu == “剪刀” || shu == “石头” || shu == “布”)
{
int ren = 0;
switch (shu)
{
case “剪刀”:
ren = 1;
break;
case “石头”:
ren = 2;
break;
case “布”:
ren = 3;
break;
}
Random ran = new Random();
int dian = ran.Next(1, 4);
switch (dian)
{
case 1:
Console.WriteLine(“Computer出剪刀”);
break;
case 2:
Console.WriteLine(“Computer出石头”);
break;
case 3:
Console.WriteLine(“计算机出布”);
break;
}
int jie = ren – dian;
if (jie == 0)
{
return “本轮平局!”;
}
else if (jie == 1 || jie == -2)
{
return “本轮胜出!”;
}
else
{
return “本轮失利!”;
}
}
else
{
return “输入有误!”;
}
}
public void tizhong()
{
Console.Write(“请输入性别”);
string s = Console.ReadLine();
Console.Write(“请输入体重”);
double t = double.Parse(Console.ReadLine());
Console.Write(“请输入身高”);
double g = double.Parse(Console.ReadLine());
if (s == “男”)
{
double n = t – g + 100;
if (n > 3 && n <= -3)
{
Console.WriteLine(“您是专门的事业体重”);
}
else if (n > 3)
{
Console.WriteLine(“您的体重偏胖”);
}
else
{
Console.WriteLine(“您的体重偏瘦”);
}
}
else if (s == “女”)
{
double n = t – g + 110;
if (n > 3 && n <= -3)
{
Console.WriteLine(“您是标准体重”);
}
else if (n > 3)
{
Console.WriteLine(“您的体重偏胖”);
}
else
{
Console.WriteLine(“您的体重偏瘦”);
}
}
else
{
Console.WriteLine(“您的输入有误”);
}
Console.ReadLine();
}

Console.WriteLine(“请输入竞选班长的代码1、贰、三、肆、5来分别表示 张3,
李4, 王5, 赵6, 冯七”);

 

 

static void Main(string[] args)
{
务求:写叁个函数,计算体重是不是正规
函数须要多个输入值,分别为性别、体重kg、身高cm
男:身高-100=体重±3kg
女:身高-110=体重±3kg
Console.Write(“请输入性别”);
string s = Console.ReadLine();
Console.Write(“请输入体重”);
double t = double.Parse(Console.ReadLine());
Console.Write(“请输入身高”);
double g = double.Parse(Console.ReadLine());
if (s == “男”)
{
double n = t – g + 100;
if (n > 3 && n <= -3)
{
Console.WriteLine(“您是专门的学业体重”);
}
else if (n > 3)
{
Console.WriteLine(“您的体重偏胖”);
}
else
{
Console.WriteLine(“您的体重偏瘦”);
}
}
else if (s == “女”)
{
double n = t – g + 110;
if (n > 3 && n <= -3)
{
Console.WriteLine(“您是标准体重”);
}
else if (n > 3)
{
Console.WriteLine(“您的体重偏胖”);
}
else
{
Console.WriteLine(“您的体重偏瘦”);
}
}
else
{
Console.WriteLine(“您的输入有误”);
}
Console.ReadLine();
Program hanshu = new Program();
hanshu.tizhong();

int[] shuzu = new int[20];
for (int i = 1; i <= 20; i++)
{
Console.Write(“请第” + i + “位同学来进展投票:”);
shuzu[i – 1] = int.Parse(Console.ReadLine());
}
Console.WriteLine(“投票甘休!按下回车起初总计票数!”);
Console.ReadLine();
int zhangsan = 0, lisi = 0, wangwu = 0, zhaoliu = 0, fengqi = 0, zuofei
= 0;
for (int i = 0; i < 20; i++)
{
switch (shuzu[i])
{
case (int)Houxuanren.one:
4858.com ,zhangsan++;
break;
case (int)Houxuanren.two:
lisi++;
break;

 

 

率先对于各州的类实行最先化
Program hanshu = new Program();
hanshu.LeiJia();
int sum = hanshu.LeiJia1();
在那些数值上再加13分
sum += 10;

case (int)Houxuanren.three:
wangwu++;
break;

int sum= hanshu.LeiJia2(5);

 

Console.WriteLine(sum);
Console.ReadLine();

case (int)Houxuanren.four:
zhaoliu++;
break;

hanshu.LeiJia3(5);

 

Console.Write(“请输入a=”);
double a = double.Parse(Console.ReadLine());
Console.Write(“请输入b=”);
double b = double.Parse(Console.ReadLine());
Console.Write(“请输入c=”);
double c = double.Parse(Console.ReadLine());
double max = hanshu.Max( hanshu.Max(a,b),c);

case (int)Houxuanren.five:
fengqi++;
break;
default:
zuofei++;
break;
}

Console.WriteLine(max);
Console.ReadLine();

 

输入邮箱账号,剖断是不是格式精确
Program han = new Program();
han.you();

}
if (zhangsan > lisi && zhangsan > wangwu && zhangsan > zhaoliu
&& zhangsan > fengqi)
{
Console.WriteLine(“张三胜出!票数为” + zhangsan);
}
else if (lisi > zhangsan && lisi > wangwu && lisi > zhaoliu &&
lisi > fengqi)
{
Console.WriteLine(“李4胜出!票数为” + lisi);
}
else if (wangwu > lisi && wangwu > zhangsan && wangwu > zhaoliu
&& wangwu > fengqi)
{
Console.WriteLine(“王伍胜出!票数为” + wangwu);
}
else if (zhaoliu > lisi && zhaoliu > wangwu && zhaoliu >
zhangsan && zhaoliu > fengqi)
{
Console.WriteLine(“赵6胜出!票数为” + zhaoliu);
}
else if (fengqi > lisi && fengqi > wangwu && fengqi > zhaoliu
&& fengqi > zhangsan)
{
Console.WriteLine(“冯7胜出!票数为” + fengqi);
}
Console.WriteLine(“作废的票数为:” + zuofei);
Console.ReadLine();

string yx = han.you2( );
Console.WriteLine(yx);
Console.ReadLine();

 

 

 

Console.WriteLine(“请输入邮箱地址”);
string yx = han.you3(Console .ReadLine ());
Console.WriteLine(yx);
Console.ReadLine();

 

Console.WriteLine(“请输入邮箱地址”);
han.you4(Console .ReadLine ());

}
}
}

 

 

渴求输入班级人数,依照人数输入每种人的分数
鉴于这么些班都以少数民族,所以都亟需加十二分
加拾贰分的经过要求用到函数
Console.Write(“请输入班级人数:”);
int a = int.Parse(Console.ReadLine());
double [] score =new double [a];
for (int i = 0; i < a; i++)
{
Console.Write(“请输入第{0}个人的分数:”,i+一);
score[i] = double.Parse(Console.ReadLine());
}
Console.WriteLine(“全体学生疏数输入实现,请按回车键继续!”);
Console.ReadLine();
初始化
Program hanshu = new Program();
score = hanshu.JiaFen(score);

foreach (double aa in score)
{
Console.WriteLine(aa);
}
Console.ReadLine();

 

猜拳:
人机对阵
剪刀 1
石头 2
包袱 3
人输入:(剪刀、石头、布)
0 平局
1 赢了
-1 输了
-2 赢了
2 输了
Console.Write(“请输入您出什么拳(剪刀、石头、布):”);
string shu = Console.ReadLine();

if (shu == “剪刀” || shu == “石头” || shu == “布”)
{
int ren = 0;
switch (shu)
{
case “剪刀”:
ren = 1;
break;
case “石头”:
ren = 2;
break;
case “布”:
ren = 3;
break;
}
Random ran = new Random();
int dian = ran.Next(1, 4);
switch (dian)
{
case 1:
Console.WriteLine(“Computer出剪刀”);
break;
case 2:
Console.WriteLine(“计算机出石头”);
break;
case 3:
Console.WriteLine(“计算机出布”);
break;
}
int jie = ren – dian;
if (jie == 0)
{
Console.WriteLine(“本轮平局!”);
}
else if (jie == 1 || jie == -2)
{
Console.WriteLine(“本轮胜出!”);
}
else
{
Console.WriteLine(“本轮退步!”);
}
}
else
{
Console.WriteLine(“输入有误!”);
}

Console.ReadLine();

 

输入进程中若出错
for (int i = 1; i > 0; i++)
{
Console.Write(“请输入是要么不是!”);
string ss = Console.ReadLine();
if (ss == “是” || ss == “不是”)
{
break;
}
else
{
Console.WriteLine(“输入有误!请重新输入!”);
}
}
输入年月日,查看时间日期格式是或不是科学

for (int i = 1; i > 0; i++)
{
Console.Write(“请输入年份:”);
int year = int.Parse(Console.ReadLine());
if (year >= 0 && year <= 9999)
{
for (int a = 1; a > 0; a++)
{
Console.Write(“请输入月份:”);
int month = int.Parse(Console.ReadLine());
if (month >= 1 && month <= 12)
{
for (int b = 1; b > 0; b++)
{
Console.Write(“请输入日期:”);
int day = int.Parse(Console.ReadLine());
if (day >= 1 && day <= 31)
{
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8
|| month == 10 || month == 12)
{
Console.WriteLine(“您输入的日子格式正确,您输入的日期是:{0}年{1}月{二}日”,
year, month, day);
break;
}
else
{
if (month == 4 || month == 6 || month == 9 || month == 11)
{
if (day == 31)
{
Console.WriteLine(“您输入的日期错误,请重新输入!”);
continue;
}
else
{
Console.WriteLine(“您输入的日期格式精确,您输入的日子是:{0}年{一}月{二}日”,
year, month, day);
break;
}
}
else
{
if (day <= 28)
{
Console.WriteLine(“您输入的日期格式准确,您输入的日期是:{0}年{一}月{二}日”,
year, month, day);
break;
}
else
{
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
{
if (day == 29)
{
Console.WriteLine(“您输入的日子格式准确,您输入的日期是:{0}年{一}月{二}日”,
year, month, day);
break;
}
else
{
Console.WriteLine(“您输入的日期错误,请重新输入!”);
continue;
}
}
else
{
Console.WriteLine(“您输入的日期错误,请重新输入!”);
continue;
}
}
}
}
}
else
{
Console.WriteLine(“您输入的日子错误,请重新输入!”);
continue;
}
}
a = -10;
}
else
{
Console.WriteLine(“您输入的月度错误,请重新输入!”);
continue;
}
}
}
else
{
Console.WriteLine(“您输入的年份错误,请重新输入!”);
continue;
}
i = -10;
}Console.ReadLine();

 

for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
if (j == 3)
{
break;//break跳出近来的轮回
}
Console.Write(“■”);

}
Console.WriteLine();
}

Console.ReadLine();

}
}
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图
Copyright @ 2010-2019 美高梅手机版4858 版权所有