输入n个成绩,求大于90分人数 c#
时间: 2024-05-06 13:18:48 浏览: 157
以下是一个 C# 的代码示例,实现了输入 n 个成绩并且统计大于 90 分的人数:
```csharp
using System;
class Program
{
static void Main(string[] args)
{
Console.Write("请输入成绩个数:");
int n = int.Parse(Console.ReadLine());
int count = 0;
for (int i = 0; i < n; i++)
{
Console.Write($"请输入第 {i + 1} 个成绩:");
int score = int.Parse(Console.ReadLine());
if (score > 90)
{
count++;
}
}
Console.WriteLine($"大于 90 分的人数为:{count}");
}
}
```
在这个程序中,我们首先通过 `Console.ReadLine()` 方法获取用户输入的成绩个数 `n`。然后使用一个 `for` 循环,循环 `n` 次,每次获取用户输入的成绩,并且判断是否大于 90 分。如果大于 90 分,则将计数器 `count` 加 1。最后输出大于 90 分的人数。
相关问题
c#输入十个学生成绩 求最高 最低平均
在C#中,你可以创建一个简单的控制台应用程序来输入10个学生的成绩,并计算出最高分、最低分以及平均分。以下是一个基本步骤的示例:
```csharp
using System;
class Program
{
static void Main(string[] args)
{
double[] scores = new double[10]; // 创建一个可以存储10个成绩的数组
double maxScore = double.MinValue; // 初始化最高分为负无穷大
double minScore = double.MaxValue; // 初始化最低分为正无穷大
Console.WriteLine("请输入10个学生的成绩:");
for (int i = 0; i < 10; i++)
{
Console.Write($"第{i + 1}名的成绩: ");
scores[i] = Convert.ToDouble(Console.ReadLine()); // 读取用户输入并转换成double类型
if (scores[i] > maxScore) // 更新最高分
maxScore = scores[i];
if (scores[i] < minScore) // 更新最低分
minScore = scores[i];
}
double averageScore = CalculateAverage(scores); // 计算平均分
Console.WriteLine("\n最高分: " + maxScore);
Console.WriteLine("最低分: " + minScore);
Console.WriteLine("平均分: " + averageScore);
Console.ReadLine(); // 等待用户按下回车键后关闭窗口
}
static double CalculateAverage(double[] scores)
{
double sum = 0;
foreach (double score in scores)
sum += score;
return sum / scores.Length;
}
}
```
在这个程序中,我们首先创建一个数组来存储学生分数,然后通过循环读取用户的输入,并更新最高分和最低分。最后计算平均分并打印结果。
输人n(n<10),然后输入n个成绩,求其中60分以上的人数
好的,你可以参考下面的 C# 代码实现:
```csharp
using System;
class Program {
static void Main(string[] args) {
Console.Write("请输入成绩数量 n:");
int n = int.Parse(Console.ReadLine());
int count = 0;
for (int i = 0; i < n; i++) {
Console.Write($"请输入第 {i+1} 个成绩:");
int score = int.Parse(Console.ReadLine());
if (score >= 60) {
count++;
}
}
Console.WriteLine($"60 分以上的成绩数量为:{count}");
}
}
```
代码思路:首先输入成绩数量 `n`,然后循环输入 `n` 个成绩。在循环中,如果当前输入的成绩大于等于 60 分,则计数器 `count` 加一。最后输出 `count` 的值即可。
阅读全文
相关推荐
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)