課程
/后端開發
/C#
/C#開發輕松入門
如果實戰中名字和分數在數組中的位置并沒有一一對應時怎么辦呢?
2024-02-01
源自:C#開發輕松入門 6-2
正在回答
using System;
using System.Collections.Generic;
using System.Text;
namespace projAboveAvg
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? string[,]arr={{"景珍","90"},{"林慧洋","65"},{"成蓉","88"},{"洪南昌","70"},{"龍玉民","46"},{"單江開","81"},{"田武山","100"},{"王三明","68"},};
? ? ? ? ? ? int sum=0;
? ? ? ? ? ? for(int i=0;i<arr.GetLength(0);i++){
? ? ? ? ? ? ? ? ?sum+=int.Parse(arr[i,1]);
? ? ? ? ? ? }
? ? ? ? ? ? int avg=sum/arr.GetLength(0);
? ? ? ? ? ? Console.Write("平均分是{0},高于平均分的有:",avg);
? ? ? ? ? ? ? ? if(int.Parse(arr[i,1])>avg){
? ? ? ? ? ? ? ? ? ? Console.Write(arr[i,0]+" ");
? ? ? ? ? ? ? ? }
? ? ? ? }
? ? }
}
舉報
本門課程是C#語言的入門教程,將帶你輕松入門.NET開發
6 回答如何在分數數組中查找最高分
2 回答數組元素牽引和名字輸出
1 回答老師在嗎?用二維數組還是一維數組效率比較高呢?我現在用的是二維數組,代碼如下
3 回答請問在數組中查找最高值是怎么計算的?
3 回答這道題如果用二維數組的話該怎么作?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2024-04-10
using System;
using System.Collections.Generic;
using System.Text;
namespace projAboveAvg
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? string[,]arr={{"景珍","90"},{"林慧洋","65"},{"成蓉","88"},{"洪南昌","70"},{"龍玉民","46"},{"單江開","81"},{"田武山","100"},{"王三明","68"},};
? ? ? ? ? ? int sum=0;
? ? ? ? ? ? for(int i=0;i<arr.GetLength(0);i++){
? ? ? ? ? ? ? ? ?sum+=int.Parse(arr[i,1]);
? ? ? ? ? ? }
? ? ? ? ? ? int avg=sum/arr.GetLength(0);
? ? ? ? ? ? Console.Write("平均分是{0},高于平均分的有:",avg);
? ? ? ? ? ? for(int i=0;i<arr.GetLength(0);i++){
? ? ? ? ? ? ? ? if(int.Parse(arr[i,1])>avg){
? ? ? ? ? ? ? ? ? ? Console.Write(arr[i,0]+" ");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? }
}