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