C#基于面向过程计算加权平均分的方法
程序员文章站
2023-11-20 21:40:28
本文实例讲述了c#基于面向过程计算加权平均分的方法。分享给大家供大家参考。具体如下:
using system;
using system.collection...
本文实例讲述了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#程序设计有所帮助。
推荐阅读