实习期间和同事做的一个东东~兴奋了好久 using System;
namespace xx { class xianxing { [STAThread]//定义入口点; static void Main(string[] args) { int [,]arr=new int[100,2]; int i,j,n; Console.Write("please input a number: "); n=Convert.ToInt32(Console.ReadLine()); Console.WriteLine("please input the numbers"); for(i=0;i<n;i++) { for(j=0;j<2;j++) arr[i,j]=Convert.ToInt32(Console.ReadLine()); } float avg_x=0,avg_y=0,sum_x=0,sum_y=0; for(i=0;i<n;i++) { sum_x=sum_x+arr[i,0]; avg_x=sum_x/n; } for(i=0;i<n;i++) { sum_y=sum_y+arr[i,1]; avg_y=sum_y/n; } float l_xx=0,l_yy=0,l_xy=0; float a,b; double r; for(i=0;i<n;i++) { l_xx=(arr[i,0]-avg_x)*(arr[i,0]-avg_x); l_yy=(arr[i,1]-avg_y)*(arr[i,1]-avg_y); l_xy=(arr[i,0]-avg_x)*(arr[i,1]-avg_y); } b=l_xy/l_xx; a=avg_y-b*avg_x; r=l_xy/Math.Sqrt(l_xx*l_yy); Console.WriteLine("a={0};",a); Console.WriteLine("b={0};",b); Console.WriteLine("r={0};",r); } } } 大家看看有什么地方需要改进的波