ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [C++] Recursion 재귀함수
    Programming/C++ 2020. 1. 3. 15:31
    /*자연수 찍기*/
    
    #define _CRT_SECURE_NO_WARNINGS
    #include<stdio.h>
    #include<vector>
    #include<algorithm>
    
    using namespace std;
    
    void recur(int x) {
    	if (x == 0) return; // return 해버려
    	else {
    		recur(x - 1);
    		printf("%d ", x);
    	}
    }
    
    int main() {
    	int n;
    	scanf("%d", &n);
    	recur(n);
    	return 0;
    }

     

    /*2진수 찍기*/
    
    #define _CRT_SECURE_NO_WARNINGS
    #include<stdio.h>
    #include<vector>
    #include<algorithm>
    
    using namespace std;
    void recur(int x) {
    	if (x == 0) return;
    	else {
    		recur(x / 2);
    		printf("%d", x % 2);
    	}
    }
    int main() {
    	int n;
    	scanf("%d", &n);
    	recur(n);
    	return 0;
    }

    'Programming > C++' 카테고리의 다른 글

    [C++] DFS 깊이우선탐색  (0) 2020.01.05
    [C++] STACK  (0) 2020.01.02
    [C++] Vector  (0) 2019.12.23
Designed by Tistory.