C#/C# 연습

Array : Input, MaxMin (입력, 최대값 최소값)

HicKee 2022. 11. 29. 09:47

문제3
배열의 요소 수와 각 요소의 값을 입력하면 실행결과와 같이 
각 요소의 값을 표시하는 프로그램을 작성하시오.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace pr_array_02 {
    internal class Program {
        static void Main(string[] args) {

            int input = int.Parse(Console.ReadLine());

            int[] arr = new int[input];

            for (int i = 0; i < arr.Length; i++) {
                arr[i] = int.Parse(Console.ReadLine());
            }

            for (int i = 0; i < arr.Length; i++) {
                Console.WriteLine("arr["+i+"] = " + arr[i] );
            }
            Console.WriteLine();
            Console.WriteLine("arr = [{0}]",string.Join(",",arr));
        }
    }
}

문제 4

아래와 같이 출력되도록 프로그램을 작성하시오.
타입 변수명 설명
int[] score {79, 88, 91, 33, 100, 55, 95} 으로 초기화

최대값 :100
최소값 :33

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace pr_arrary_03 {
    internal class Program {
        static void Main(string[] args) {

            int[] score = { 79, 88, 91, 33, 100, 55, 95 };

            int min = score[0];
            int max = score[0];

            for (int i = 0; i < score.Length; i++) {

                if (min > score[i]) {
                    min = score[i];
                }
                if (max < score[i]) {
                    max= score[i];
                }
            }

            Console.WriteLine("최소값 : " + min);
            Console.WriteLine("최대값 : " + max);

        }
    }
}

'C# > C# 연습' 카테고리의 다른 글

Array : Sort, Reverse (정렬)  (0) 2022.11.30
Array : Combine, Random (섞기, 랜덤)  (0) 2022.11.29
Array : Length input, Random (배열수 입력, 난수)  (0) 2022.11.28
for, While : Buger (버거)  (0) 2022.11.28
Operation : 연산자  (0) 2022.11.28