これはC#(ver 7.2)第六章練習問題です.


練習問題1
Square()メソッドを実装してプログラムを完了します.
数字を入力してください:3
結果:9
数字を入力してください:34.2
結果:1169.64
using System;

namespace Ex6_01
{
    class MainApp
    {
        static double Square(double arg)
        {
            return arg *= arg;
        }

        static void Main(string[] args)
        {
            Console.Write("수를 입력하세요 : ");
            string input = Console.ReadLine();
            double arg = double.Parse(input);

            Console.WriteLine("결과 : {0}", Square(arg));
        }
    }
}
なんてことだ
練習問題
using System;

namespace Ex6_02
{
    class MainApp
    {
        static void Main(string[] args)
        {
            double mean = 0;

            Mean(1, 2, 3, 4, 5, ref mean);

            Console.WriteLine("평균 : {0}", mean);
        }

        public static void Mean(double a, double b, double c, double d, double e, ref double mean)
        {
            mean = (a + b + c + d + e) / 5;
        }
    }
}
なんてことだ
練習問題
using System;

namespace Ex6_3
{
    class MainApp
    {
        public static void Main()
        {
            int a = 3;
            int b = 4;
            int resultA = 0;

            Plus(a, b, out resultA);

            Console.WriteLine("{0} + {1} = {2} ", a, b, resultA);

            double x = 2.4;
            double y = 3.1;
            double resultB = 0;

            Plus(x, y, out resultB);

            Console.WriteLine("{0} + {1} = {2}", x, y, resultB);
        }

        public static void Plus(int a, int b, out int c)
        {
            c = a + b;
        }

        public static void Plus(double a, double b, out double c)
        {
            c = a + b;
        }
    }
}