C#

[howto] C# - 사용자 입력값 더하기 ★ (Add Two Numbers)

4,271

※ 예제2처럼, 사용자 입력값 받아 처리하는 게 훨씬 프로그램이 유용.


[예제1] 고정 숫자로 덧셈 연산.

 

using System;

namespace Homzzang

{

  class Program

  {

    static void Main(string[] args)

    {

      int x = 3;

      int y = 4;

      int sum = x + y;

      Console.WriteLine(sum); // 7

    }

  }

}

 

결과값: 7


[예제2] 사용자 입력값 받아 덧셈. 

 

using System;

namespace Homzzang

{

    class Program

    {

        static void Main(string[] args)

        {

            int x, y, sum; 

            Console.WriteLine("숫자 입력:");

            x = Convert.ToInt32(Console.ReadLine()); 

            Console.WriteLine("숫자 입력:");

            y = Convert.ToInt32(Console.ReadLine()); 

            sum = x + y;

            Console.WriteLine(sum);

        }

    }

}

 

결과값: 사용자 입력값에 따라 다름.

cf. (C++Java) 경우, 사용자 입력값 받아 더하기.



분류 제목
howto C# - 사용자 입력값 더하기 ★ (Add Two Numbers)
목록
 홈  PC버전 로그인 일본어
그누앞단언어
그누뒷단언어
그외코딩언어
그누보드
제작의뢰
Q&A
커뮤니티 2
웹유틸
회원센터
홈짱닷컴 PC버전 로그인