2016년 12월 8일 목요일

[C#] 유니티 재귀함수 (Feat.구구단) ([C#] Unity Recursive function(Feat.multiplication table)

using UnityEngine;
using System.Collections;

public class Data : MonoBehaviour {

    int num_1, num_2;

    void Start()
    {
        num_1 = 2;
        num_2 = 1;

        mul(num_1, num_2);
    }
    public int mul(int a, int b)
    {
        int num = 0;
        if (b == 10)
        {
            a += 1;
            b = 1;
            return mul(a, b + 1);
        }

        if (a > 10)
        {
            return 0;
        }
        num = a * b;
        show(a, b, num);
        return mul(a , b + 1);
    }

    public void show(int a, int b, int num)
    {
        Debug.Log(a + "단 :" + a + " x " + b + " = " + num);        
    }
}
- 간단한 코드라 자세한 설명은 생략한다.

결과

댓글 없음:

댓글 쓰기

아이디어 및 질문 외에 댓글은 사양합니다.