首页 > 编程 > C# > 正文

C#基于面向过程计算加权平均分的方法

2020-01-24 01:37:00
字体:
来源:转载
供稿:网友

本文实例讲述了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#程序设计有所帮助。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表