这篇文章主要介绍了C#基于面向过程计算加权平均分的方法,涉及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#程序设计有所帮助。
新闻热点
疑难解答