C#

내일배움 C# 달리기반 Lv2 문제5,6

hunhun4949 2024. 8. 19. 20:43

5. 이중 반복문을 사용한 구구단 출력

using System;
using System.Numerics;
using static System.Console;


namespace Practice1
{
    internal class Practice
    {
        static void Main(string[] args)
        {

            WriteLine("구구단 세로로 출력!");
            for (int i = 1; i <= 9; i++)
            {
                for (int j = 2; j <= 9; j++)
                {
                    Write($"{j} x {i} = {i * j}\t");
                }
                WriteLine();
            }

            WriteLine("\n구구단 가로로 출력!");
            for (int i = 2; i<=9; i++)
           {
                for(int j=1;j<=9; j++)
                {
                    Write($"{i} x {j} = {i * j}\t");
                }
                WriteLine();
           }
        }
    }
}

 

 

6. 배열 요소의 최대값과 최소값 찾기

using System;
using System.Numerics;
using static System.Console;


namespace Practice1
{
    internal class Practice
    {
        static void Main(string[] args)
        {
            int[] numbers = { 10, 30, 20, 40, 50, 80, 0, 70 };

            int min = numbers[0];
            int max = numbers[0];
            for(int i=1; i<numbers.Length; i++)
            {
                if (numbers[i] < min)
                {
                    min = numbers[i]; 
                }
                if (numbers[i] > max)
                {
                    max = numbers[i];
                }
            }

            WriteLine($"주어진 숫자 배열에서 최소값 : {min}");
            WriteLine($"주어진 숫자 배열에서 최대값 : {max}");
        }
    }
}