-
using System;
using System.Collections.Generic;
using System.Text;
namespace projAboveAvg
{
class Program
{
static void Main(string[] args)
{
string[] name = new string[]{"景珍","林惠洋","成蓉","洪南昌","龙玉民","单江开","田武山","王三明"};
int[] score = new int[]{90,65,88,70,46,81,100,68};
int sum = 0,avg;
for(int i=0;i<score.Length;i++)
{
sum += score[i];
}
avg = sum/score.Length;
Console.WriteLine("平均分是{0},高于平均分的有:",avg);
for(int j=0;j<score.Length;j++)
{
if(score[j]>avg)
{
Console.Write(name[j]+" ");
}
}
}
}
}
查看全部 -
using System;
using System.Collections.Generic;
using System.Text;
namespace projGetMaxScore
{
class Program
{
static void Main(string[] args)
{
string[,] info = new string[8, 2] { { "吴松", "89" }, { "钱东宇", "90" }, { "伏晨", "98" }, { "陈陆", "56" }, { "周蕊", "60" }, { "林日鹏", "91" }, { "何昆", "93" }, { "关欣", "85" } };
/*int y=int.Parse(info[2,1]);
Console.WriteLine(y);*/
int x=0;
for(int i=0;i<8;i++)
{
if(int.Parse(info[i,1])>int.Parse(info[x,1]))
{
x=i;
}
else
{
x=x+0;
}
}
Console.WriteLine("分数最高的是"+info[x,0]+",分数是"+info[x,1]);
}
}
}查看全部 -
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
string[] name = new string[3];
int[] score = new int[3];
for (int i = 0; i < name.Length; i++)
{
Console.Write("请输入第" + (i + 1) + "个同学的姓名:");
name[i] = Console.ReadLine();
Console.Write("请输入第" + (i + 1) + "个同学的成绩:");
score[i] =int.Parse (Console.ReadLine());
}
int sum = 0, avg;
for(int i=0;i<name.Length;i++)
{
sum += score[i];
}
avg = sum / name.Length;
Console.WriteLine("总分:{0},平均分:{1}",sum,avg);
}
}
}
查看全部 -
string name;
Console.Write("请输入您的姓名:");
name = Console.ReadLine();
Console.WriteLine("您好,{0}!",name);
查看全部 -
using System;
using System.Collections.Generic;
using System.Text;
namespace projGetMaxScore
{
class Program
{
static void Main(string[] args)
{
string[]name=new string[]{"吴松","钱东宇","伏晨","陈陆","周蕊","林日鹏","何昆","关欣"} ;
int[]score=new int[]{89,90,98,56,60,91,93,85};
int max=0;
for(int i=0;i<score.Length;i++)
{
if(score[max]<score[i])
{
max=i;
}
}
Console.Write("分数最高的是{0},分数是{1}",name[max],score[max]);
}
}
}
查看全部 -
查看全部
-
for 循环使我们可以通过索引访问数组元素;而 foreach 循环则可以不依赖索引而读取每一个数组元素。
int [] num={55,66,77,88,99,111,} ;
foreach(int x in num)
{
Console.Write(x+" ");
}
查看全部 -
hasNbr的初始值为false
查看全部 -
int x = 6;
x += 2;x的值为8
x -= 2;x的值为4
x *= 2;x的值为12
x /= 2;x的值为3
x %= 2;x 的值为0
查看全部 -
foreach(数据类型 迭代变量 in 数组名)
查看全部 -
static void Main(string[] args)
{
for(int i=1;i<8;i++){
for(int j=1;j<8;j++){
if(j==i||i+j==8)
Console.Write("O");
else
Console.Write(".");
}
Console.WriteLine(" ");
}
}
找出规律 解决问题
查看全部 -
double 关键字表示一种数据类型 双精度浮点型 const 声明常量的关键字
查看全部 -
i代表行
x代表列
查看全部 -
string[,] name = { { "景珍", "90" }, { "林惠阳", "65" }, { "成蓉", "88" }, { "洪南昌", "70" }, { "龙玉民", "46" }, { "单江开", "81" }, { "田武山", "100" }, { "王三明", "68" } };
int score = 0;
for (int i=0;i<name.GetLongLength(0);i++)
{
score += int.Parse(name[i,1]);
}
int score1 = score / (int)name.GetLongLength(0);
Console.Write("平均分是{0}",score1);
Console.Write(",高于平均分的有:");
for (int i=0;i<name.GetLongLength(0);i++)
{
if (int.Parse(name[i,1])>score1)
{
Console.Write(name[i,0]+" ");
}
}
查看全部 -
int[] num = new int[] { 3, 34, 43, 2, 11, 19, 30, 55, 20 };
//请完善代码,判断数组中有没有7的整倍数
bool pp = true;
for (int i=0;i<num.Length;i++)
{
if (num[i]%7!=0)
{
pp = false;
}
else
{
pp = true;
break;
}
}
if (!pp)
{
Console.Write("没有7的倍数!");
}
else
{
Console.Write("有7的倍数!");
}
//使用ToList实现
var qq = num.ToList();
bool pd = qq.Any(n => n % 7 == 0);
if(!pd)
{
Console.Write("没有7的倍数!");
}
查看全部
举报