관리 메뉴

bread, coffee and coding

C# D+4 본문

C#

C# D+4

DongJin lee 2021. 7. 5. 21:34

영어,국어,수학 성적이 들어있는
정수형 배열 score를 선언하세요
영어 80 국어 90 수학 95

정수형 배열 score 꼭 반복문에 활영하여 평균avg를 구해주세요
단 avg변수는 소수점 둘째자리까지 구해주세요
using System;

namespace ConsoleApp9
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] score = new int[3];
            double avg;
            int sum = 0;

            for (int i = 0; i < 3; i++)
            {
                score[i] = int.Parse(Console.ReadLine());
                sum += score[i]; //sum = sum + score[i]
            }

            avg = (double)sum / 3.0;

            Console.WriteLine(Math.Round(avg, 2));
        }
    }
}

ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
using System;

namespace ConsoleApp_break
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 10;
            do
            {
                Console.WriteLine("i:" + a);
                a -= 1;
            }
            while (a >= 0);

        }
    }
}

ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
using System;

namespace MyApp_CallByValue
{
    class Program
    {
        public static void Swap(int a, int b)
        {
            Console.WriteLine($"a: {a}, b;{b}");
            int temp = b;
            b = a;
            a = temp;
            Console.WriteLine($"a: {a}, b;{b}");
        }
        static void Main(string[] args)
        {
            int x = 3, y = 4;
            Console.WriteLine($"x: {x}, y;{y}");
            Swap(x, y);
            Console.WriteLine($"x: {x}, y;{y}");
        }
    }
}

--------------------------------------------------------------------------

'C#' 카테고리의 다른 글

C# D+5  (0) 2021.07.05
C# D+3  (0) 2021.07.05
C# D+2  (0) 2021.07.05
C# D+1  (0) 2021.05.05