using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace OUT函数 { class Program { //public void outzhi(double a, double b, double c, out double j1, out double j2) public void outzhi(double a, double b, double c, out string j1, out string j2) { double de = b * b - 4 * a * c; if (de < 0) { Console.WriteLine("函数没有实根"); j1 = j2 = ""; } else { double x1 = (-b + Math.Sqrt(de)) / (2 * a); double x2 = (-b - Math.Sqrt(de)) / (2 * a); if (de == 0) { Console.WriteLine("方程有两个相同的实根"); j1 = j2 = x1.ToString(); } else { Console.WriteLine("方程有两个不同的实根"); //Console.Write("x1=" + x1); Console.Write(" x2=" + x2); j1 = x1.ToString(); j2 = x2.ToString(); } } } static void Main(string[] args) { Program hanshu = new Program(); 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 j1 = 0; //double j2 = 0; string j1 = ""; string j2 = ""; hanshu.outzhi(a, b, c, out j1, out j2); Console.WriteLine("第一个根x1=" + j1); Console.Write("第二个根x2=" + j2); Console.ReadLine(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _0630下午 { class Program { public void hou() { int sum = 0; for (int i = 10; i > 0; i--) { if (i == 10) { sum = 1; } else { sum = (sum + 1) * 2; } } Console.Write(sum); } public int jiafen(int a) { a+= 10; return a; } public void jiafen2(int[] a) { int l= a.Length; for (int i = 0; i < l; i++) { a[i] += 10; } } public int [] jiafen4(int[] a) { int l = a.Length; for (int i = 0; i < l; i++) { a[i] += 10; } return a; } public void jiafen3(int[] a, out int[] b) { int l = a.Length; for (int i = 0; i < l; i++) { a [i] = a[i] + 10; } b = a; } static void Main(string[] args) { //out 传值 形式参数:只给值,不给变量名(传值) 实际参数:将变量名传给函数(传址) //out是实参 Program hanshu=new Program(); //猴子 //hanshu.hou(); //Console.ReadLine(); //输入班级人数,根据人数输入每个人的成绩 //本班都是少数民族学生,每个人+10分 //写一个专门+10分的函数,参数是这个分数的数组 Console.WriteLine("请输入班级的人数"); int renshu = int.Parse(Console.ReadLine()); int[] fen = new int[renshu]; for (int i = 0; i < renshu ;i++ ) { Console.WriteLine("请输入第{0}名同学的成绩",(i+1)); fen[i] = int.Parse(Console.ReadLine()); } //for(int i=0;i <renshu ;i++) //{ // fen[i ]= hanshu.jiafen(fen[i]); //} //hanshu.jiafen2(fen ); //hanshu.jiafen3(fen,out chengji); int []chengji=new int [renshu ]; hanshu.jiafen3(fen,out chengji ); foreach(int aa in chengji ) { Console.WriteLine(aa ); } foreach (int aa in fen ) { Console.WriteLine(aa); } Console.ReadLine(); } } }
split的使用
时间: 2024-10-05 04:38:09