Created
March 26, 2018 08:37
-
-
Save jwon0615/bd60c718e7ccdb5573d7a165dc44addd to your computer and use it in GitHub Desktop.
3_codeup_연습문제_재귀
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int fibo(int n, int a, int b){ | |
if (n==0) { | |
return a; | |
} | |
fibo(n-1, b,(a+b)%10009); | |
} | |
int main(){ | |
int n; | |
scanf("%d", &n); | |
printf("%d", fibo(n, 0, 1)); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
int sum; | |
int f(int n){ | |
if(n>0) { | |
sum = sum*10 + n%10; | |
return f(n/10); | |
} | |
else | |
return sum; | |
} | |
int main(){ | |
int a; | |
scanf("%d",&a); | |
printf("%d",f(a)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void f(int k){ | |
if(k/2) | |
f(k/2); | |
printf("%d", k%2); | |
} | |
int main(){ | |
int n; | |
scanf("%d", &n); | |
f(n); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void f(int k){ | |
if (k==1) ; | |
else{ | |
if (k%2) f(3*k+1); | |
else f(k/2); | |
} | |
printf("%d\n", k); | |
} | |
int main(){ | |
int n; | |
scanf("%d", &n); | |
f(n); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void hanoi(int k, char from, char by, char to){ | |
if(!k) return; | |
hanoi(k-1,from,to,by); | |
printf("Disk %d : %c to %c\n", k, from, to); | |
hanoi(k-1,by,from,to); | |
} | |
int main(){ | |
int n; | |
scanf("%d", &n); | |
hanoi(n,'A','B','C'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int cnt=0; | |
void hanoi(int k, char from, char by, char to){ | |
if(!k) return; | |
hanoi(k-1,from,to,by); | |
cnt++; | |
hanoi(k-1,by,from,to); | |
} | |
int main(){ | |
int n; | |
scanf("%d", &n); | |
hanoi(n,'A','B','C'); | |
printf("%d", cnt); | |
} | |
/* | |
#include <stdio.h> | |
int main(void) | |
{ | |
int n; | |
scanf("%d",&n); | |
printf("%d",(1<<n)-1); | |
} | |
#include <stdio.h> | |
int hanoi(int n){ | |
if(n==1) return 1; | |
else return 2*hanoi(n-1)+1; | |
} | |
int main(){ | |
int n; | |
scanf("%d", &n); | |
printf("%d", hanoi(n)); | |
return 0; | |
} | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
int memo[100005] = {1, 1, 2}; | |
int f(int k){ | |
if (memo[k]) return memo[k]; | |
else return memo[k] = (f(k-3) + f(k-2) + f(k-1)) % 1000; | |
} | |
int main(){ | |
int x; | |
scanf("%d", &x); | |
printf("%d", f(x)); | |
} | |
/* | |
#include <stdio.h> | |
int main(){ | |
int n,i; | |
int a[100005]; | |
scanf("%d",&n); | |
a[0]=1; | |
a[1]=1; | |
a[2]=2; | |
for(i=3;i<=n;i++) | |
a[i]=(a[i-1]+a[i-2]+a[i-3])%1000; | |
printf("%d",a[n]); | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment