标签:
class Program { public int jiecheng(int i) { if (i == 1)//函数停止继续调用的条件,函数的出口 { return i; } int sum = i * jiecheng(i-1); //i=5 //int sum = 5*jiecheng(4); //int sum = 5*(4*jiecheng(3)); //int sum = 5*(4*(3*jiecheng(2))); //int sum = 5*(4*(3*(2*jiecheng(1)))); //int sum = 5*(4*(3*(2*1))); return sum; } public double tz(double a) { double sum = 0; if(a==1) { return 2; } sum= Math.Pow(2, a); return sum; } /// <summary> /// 求生兔子,输入几个月之后 /// </summary> /// <param name="i"></param> /// <returns></returns> public int abc(int i) { int sum=0; if (i == 1) { return 2; } sum = i * 2 * abc(i - 1); return sum; } struct jiegouti { public string name; public int piao; } public void xuan() { ArrayList al=new ArrayList(); jiegouti jgt1=new jiegouti(); jiegouti jgt2 = new jiegouti(); jiegouti jgt3 = new jiegouti(); jiegouti jgt4 = new jiegouti(); jiegouti jgt5= new jiegouti(); jiegouti jgt6 = new jiegouti(); for (int i = 0; i < 20;i++ ) { Console.WriteLine("请投票(张三1,李四2,王五3,赵六4,冯七5)"); int a = int.Parse(Console.ReadLine ()); switch (a) { case 1: jgt1.piao++; break; case 2: jgt2.piao++; break; case 3: jgt3.piao++; break; case 4: jgt4.piao++; break; case 5: jgt5.piao++; break; default : jgt6.piao++; break; } } jgt1.name = "张三"; al.Add(jgt1); jgt2.name = "李四"; al.Add(jgt2); jgt3.name = "王五"; al.Add(jgt3); jgt4.name = "赵六"; al.Add(jgt4); jgt5.name = "冯七"; al.Add(jgt5); jgt6.name = "废票"; al.Add(jgt6); //冒泡排序 for(int i=0;i<6;i++) { for (int j = i; j< 5;j++ ) { jiegouti b=(jiegouti )al[i]; jiegouti b1 = (jiegouti )al[j+1]; jiegouti b2 = new jiegouti(); if (b.piao < b1.piao) { ArrayList zhong = new ArrayList(); b2.name = ""; b2.piao = 0; zhong.Add(b2 ); zhong[0] = al[i]; al[i] = al[j + 1]; al[j + 1] = zhong[0]; } } } jiegouti shuchu = new jiegouti(); shuchu = (jiegouti)al[0]; Console.WriteLine(shuchu.name + shuchu.piao); Console.WriteLine("废票" + jgt6.piao); } static void Main(string[] args) { //Program hanshu = new Program(); //Console.Write("请输入一个正整数:"); //int a = int.Parse(Console.ReadLine()); //Console.WriteLine("阶乘的结果是:"+hanshu.jiecheng(a)); //Console.ReadLine(); //编写递归函数求 2*4*6*……*(2n) 的结果 //Program sh = new Program(); //Console.WriteLine("输入n"); //int sd = int.Parse(Console.ReadLine()); //int sda = sh.abc(sd); //Console.WriteLine(sda); //Console.ReadLine(); //有雌雄一对兔子,每过一个月便可繁殖雌雄各一的一对小兔子。 //问过n个月后共有多少对兔子? //Console.Write("请输入第几个月:"); //double mm = double.Parse(Console.ReadLine()); //Program ss = new Program(); //double aa= ss.tz(mm); //Console.WriteLine("兔子的总数是:"+aa); //Console.ReadLine(); //数组 or集合 or结构体 //5个候选人竞选班长:张三,李四,王五,赵六,冯七 //班级中共有20人,20人轮流投票 //只要不是1~5之内的视为作废 统计 //最后要知道谁的票数最多,当选班长 Program hanshu = new Program(); hanshu.xuan(); Console.ReadLine(); //Program zdy = new Program(); //Console.WriteLine("请输入你想知道第几个月后的兔子数:"); //int a = int.Parse(Console.ReadLine()); //Console.WriteLine(zdy.tz(a)); //Console.ReadLine(); //2的3次方 //Console.WriteLine(Math.Pow(2,3)); //Console.ReadLine(); } }
标签:
原文地址:http://www.cnblogs.com/blueteasama/p/5655901.html