C#第二章作業
授業後の宿題どのサイクルforサイクルwhileサイクルdo whileサイクル二重forサイクルforeachサイクルを学んだかを教えてください.C#プログラムを記述し、配列int[i]number=new int[]{1,2,3,4,5}を定義する.fo'reachループ出力配列のデータを使用して、3に遭遇すると出力されないことを要求し、5に遭遇するとループコードを終了します.
3.プログラム実装1 22 333 4444 55555の効果コードは以下の通りである.
4.コードを作成して、1つのクラスの5人の学生の名前と3つの課程の試験成績を受け入れることを実現し、1人の学生の3つの課程の総成績と平均成績を計算し、学生の名前、3つの課程の試験成績、総成績と平均成績、およびクラスの試験参加人数、3つの授業の合計の最高点と平均点Studio類を出力する.
主な方法:
5.プログラムを作成し、コンピュータ部品の価格を入力し、高いものから低いものまで並べ替えて出力し、同時にこのコンピュータの最低/最高総価格コードを計算する.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace @foreach
{
class Program
{
static void Main(string[] args)
{
int[] number = new int[] { 1, 2, 3, 4, 5};
foreach (int i in number)
{
if (i == 3) {
continue;
}
if (i == 5)
{
break;
}
Console.WriteLine(i);
}
Console.ReadLine();
}
}
}
3.プログラム実装1 22 333 4444 55555の効果コードは以下の通りである.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ForXunHuan
{
class Program
{
static void Main(string[] args)
{
int i, j; //
//
for (i = 1; i <= 5; i++) {
//
for (j = 1; j <=i; j++) {
Console.Write(i); //
}
Console.WriteLine(); //
}
Console.ReadLine();
}
}
}
4.コードを作成して、1つのクラスの5人の学生の名前と3つの課程の試験成績を受け入れることを実現し、1人の学生の3つの課程の総成績と平均成績を計算し、学生の名前、3つの課程の試験成績、総成績と平均成績、およびクラスの試験参加人数、3つの授業の合計の最高点と平均点Studio類を出力する.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace
{
class Student
{
double sum = 0;
double avg = 0;
public void students()
{
Console.Write(" :");
string student = Console.ReadLine();
}
public double getScore()
{
double[] score = new double[3];
for (int i = 0; i < score.Length; i++) {
Console.Write(" {0} :",i+1);
score[i] = double.Parse((Console.ReadLine()));
sum = score[0] + score[1] + score[2];
}
return sum;
}
public void show()
{
double[] student = new double[5];
for (int i = 0; i < student.Length; i++)
{
students();
double sums = getScore();
Console.Write(" :" + sums);
double avg = sums / 3;
Console.Write(" :" + avg);
student[i] = sums;
Console.WriteLine("
");
}
int temp = 0;
foreach (int item in student)
{
if (item > temp)
{
temp = item;
}
}
double allavg, allsum = 0;
foreach (double item in student)
{
allsum += item;
}
allavg = allsum / student.Length;
Console.WriteLine(" :{0}, :{1}, {2}", student.Length, temp, allavg);
Console.ReadLine();
}
}
}
主な方法:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace
{
class Program
{
static void Main(string[] args)
{
Student student = new Student();
student.show();
}
}
}
5.プログラムを作成し、コンピュータ部品の価格を入力し、高いものから低いものまで並べ替えて出力し、同時にこのコンピュータの最低/最高総価格コードを計算する.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CPU
{
class Program
{
static void Main(string[] args)
{
//CPU GPU RAM SSD CD PLAN DISPLAY
int [] computer = new int[7]; //
int i, j; //
int temp; //
int Max = 0; //
int Min = 0; //
int Sum; //
Console.WriteLine(" :");
for (i=0; i