거듭제곱_1217

heyryu·2022년 5월 25일
0

SWEA

목록 보기
5/7

n^m 구하기 (재귀함수 이용해서!)
재귀함수 오랜만이라서 검색 좀 함,,;;

SWEA Code

import java.util.Scanner;

class Solution
{
	public static void main(String args[]) throws Exception
	{
		Scanner sc = new Scanner(System.in);
		int T = 10;
        
        for(int test_case = 1; test_case <= T; test_case++)
		{
            int i = sc.nextInt();
            int n = sc.nextInt();
            int m = sc.nextInt();
            
            int result = calc(n,m);
            System.out.println("#"+i+" "+result);
		}
	}
    //재귀함수
    public static int calc(int n, int m){
		if (m==0) return 1;
		return n*calc(n,m-1);
        }
}
profile
못하면 열심히 하는 게 당연하니까💪 [Frontend/서비스기획]

0개의 댓글