1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace OUT函数 8 { 9 class Program 10 { 11 //public void outzhi(double a, double b, double c, out double j1, out double j2) 12 public void outzhi(double a, double b, double c, out string j1, out string j2) 13 { 14 double de = b * b - 4 * a * c; 15 if (de < 0) 16 { 17 Console.WriteLine("函数没有实根"); 18 j1 = j2 = ""; 19 20 } 21 else 22 { 23 double x1 = (-b + Math.Sqrt(de)) / (2 * a); 24 double x2 = (-b - Math.Sqrt(de)) / (2 * a); 25 if (de == 0) 26 { 27 Console.WriteLine("方程有两个相同的实根"); 28 j1 = j2 = x1.ToString(); 29 } 30 else 31 { 32 Console.WriteLine("方程有两个不同的实根"); 33 //Console.Write("x1=" + x1); Console.Write(" x2=" + x2); 34 j1 = x1.ToString(); 35 j2 = x2.ToString(); 36 } 37 } 38 39 } 40 41 42 static void Main(string[] args) 43 { 44 Program hanshu = new Program(); 45 Console.Write("请输入a="); 46 double a = double.Parse(Console.ReadLine()); 47 Console.Write("请输入b="); 48 double b = double.Parse(Console.ReadLine()); 49 Console.Write("请输入c="); 50 double c = double.Parse(Console.ReadLine()); 51 //double j1 = 0; 52 //double j2 = 0; 53 string j1 = ""; 54 string j2 = ""; 55 hanshu.outzhi(a, b, c, out j1, out j2); 56 Console.WriteLine("第一个根x1=" + j1); 57 Console.Write("第二个根x2=" + j2); 58 Console.ReadLine(); 59 60 } 61 } 62 }
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace _0630下午 8 { 9 class Program 10 { 11 public void hou() 12 { 13 int sum = 0; 14 for (int i = 10; i > 0; i--) 15 { 16 if (i == 10) 17 { 18 sum = 1; 19 } 20 else 21 { 22 sum = (sum + 1) * 2; 23 } 24 } 25 Console.Write(sum); 26 } 27 28 public int jiafen(int a) 29 { 30 a+= 10; 31 return a; 32 } 33 34 public void jiafen2(int[] a) 35 { 36 int l= a.Length; 37 for (int i = 0; i < l; i++) 38 { 39 a[i] += 10; 40 } 41 } 42 43 public int [] jiafen4(int[] a) 44 { 45 int l = a.Length; 46 for (int i = 0; i < l; i++) 47 { 48 a[i] += 10; 49 } 50 return a; 51 } 52 53 public void jiafen3(int[] a, out int[] b) 54 { 55 int l = a.Length; 56 for (int i = 0; i < l; i++) 57 { 58 a [i] = a[i] + 10; 59 } 60 b = a; 61 } 62 63 static void Main(string[] args) 64 { 65 //out 传值 形式参数:只给值,不给变量名(传值) 实际参数:将变量名传给函数(传址) 66 //out是实参 67 68 Program hanshu=new Program(); 69 //猴子 70 //hanshu.hou(); 71 //Console.ReadLine(); 72 73 //输入班级人数,根据人数输入每个人的成绩 74 //本班都是少数民族学生,每个人+10分 75 //写一个专门+10分的函数,参数是这个分数的数组 76 Console.WriteLine("请输入班级的人数"); 77 int renshu = int.Parse(Console.ReadLine()); 78 int[] fen = new int[renshu]; 79 for (int i = 0; i < renshu ;i++ ) 80 { 81 Console.WriteLine("请输入第{0}名同学的成绩",(i+1)); 82 fen[i] = int.Parse(Console.ReadLine()); 83 } 84 //for(int i=0;i <renshu ;i++) 85 //{ 86 // fen[i ]= hanshu.jiafen(fen[i]); 87 //} 88 89 //hanshu.jiafen2(fen ); 90 //hanshu.jiafen3(fen,out chengji); 91 92 int []chengji=new int [renshu ]; 93 hanshu.jiafen3(fen,out chengji ); 94 foreach(int aa in chengji ) 95 { 96 Console.WriteLine(aa ); 97 } 98 foreach (int aa in fen ) 99 { 100 Console.WriteLine(aa); 101 } 102 Console.ReadLine(); 103 104 105 106 } 107 } 108 }
时间: 2024-10-10 20:04:56