#include <stdio.h>
int sumNumber(int n)
{
if(n<=1) return n;
return n+sumNumber(n-1);
}
int main()
{
int n;
scanf("%d", &n);
printf("%d\n", sumNumber(n));
}
#include <stdio.h>
void bigNumber(int n)
{
if(n<10)
{
printf("%d\n", n);
return;
}
else
{
bigNumber(n/10);
printf("%d\n",n%10);
return;
}
}
int main()
{
int n;
scanf("%d", &n);
bigNumber(n);
}
#include <stdio.h>
void bigNumber(int n)
{
if(n<10)
{
printf("%d\n", n);
return;
}
else
{
` printf("%d\n",n%10); //출력을 먼저
bigNumber(n/10);
return;
}
}
int main()
{
int n;
scanf("%d", &n);
bigNumber(n);
}
#include <stdio.h>
int maxNum(int num, int* maxNumber) //int* maxNumber = int maxNumber[]
{
int m;
if (num == 0)
return maxNumber[0];
m = maxNum(num-1, maxNumber);
if (m > maxNumber[num])
return m;
else
return maxNumber[num];
}
int main()
{
int num;
scanf("%d",&num);
int maxNumber[20];
for(int i=0;i<num;i++)
scanf("%d", &maxNumber[i]); //maxNumber+i , 배열의 이름이 시작주소와 같기 때문
int result = maxNum(num-1, maxNumber);
printf("%d", result);
}
#include <stdio.h>
void hanoi(int n,char from, char tmp, char to)
{
if(n==1)
printf("%c %c\n",from,to);
else
{
hanoi(n-1,from,to,tmp);
printf("%c %c\n",from,to);
hanoi(n-1,tmp,from,to);
}
}
int main()
{
int n;
scanf("%d",&n);
hanoi(n,'A','B','C');
}
#include <stdio.h>
int gcd(int i, int j)
{
if(i==0)
return j;
else if(j==0)
return i;
else
{
if(i>j)
{
printf("gcd(%d, %d %% %d)\n",j,i,j);
gcd(j,i%j);
}
else
{
printf("gcd(%d, %d %% %d)\n",i,j,i);
gcd(i,j%i);
}
}
}
int main()
{
int i,j;
scanf("%d %d", &i, &j);
printf("%d",gcd(i,j));
}
이어서 ...