C#基于面向过程计算加权平均分的方法
本文实例讲述了C#基于面向过程计算加权平均分的方法。分享给大家供大家参考。具体如下:
usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Text; namespaceConsoleApplication1 { classProgram { staticvoidMain(string[]args) { Console.WriteLine("输入你的总共课程数:"); intscore_number=0; stringscore_temp=Console.ReadLine(); score_number=Convert.ToInt32(score_temp); double[]score; score=newdouble[score_number]; double[]unit; unit=newdouble[score_number]; doublesum=0; doubletotal_credit=0; Console.WriteLine("请输入你的各个分数:"); for(inti=0;i<=score_number-1;i++) { stringtemp=Console.ReadLine(); score[i]=Convert.ToDouble(temp); } Console.WriteLine("请输入你的各个权重:"); for(inti=0;i<=score_number-1;i++) { stringtemp=Console.ReadLine(); unit[i]=Convert.ToDouble(temp); } for(inti=0;i<=score_number-1;i++) { sum=sum+(score[i]*unit[i]); } for(inti=0;i<=score_number-1;i++) { total_credit=total_credit+unit[i]; } doubleresult=0; result=sum/total_credit; Console.WriteLine("您的加权评均分为:"); Console.WriteLine(result); Console.ReadKey(); } } }
希望本文所述对大家的C#程序设计有所帮助。