问题八十五:数值自乘递归
[plain]
#include <stdio.h>
int recursion(int m, int n);
int main()
{
int m;
int n;
int result;
printf("please enter m=");
scanf("%d", &m);
printf("please enter n=");
scanf("%d", &n);
result=recursion(m, n);
printf("%d^%d==%d\n", m, n, result);
return 0;
}
int recursion(int m, int n) //递归
{
int sum;
if(n==1)
{
sum=m;
}
else if(n==2)
{
sum=m*m;
}
else
{
if(n%2==0)
{
sum=recursion(m, n-2)*recursion(m, 2);
}
else
{
sum=recursion(m, n-1)*recursion(m, 1);
}
}
return sum;
}
#include <stdio.h>
int recursion(int m, int n);
int main()
{
int m;
int n;
int result;
printf("please enter m=");
scanf("%d", &m);
printf("please enter n=");
scanf("%d", &n);
result=recursion(m, n);
printf("%d^%d==%d\n", m, n, result);
return 0;
}
int recursion(int m, int n) //递归
{
int sum;
if(n==1)
{
sum=m;
}
else if(n==2)
{
sum=m*m;
}
else
{
if(n%2==0)
{
sum=recursion(m, n-2)*recursion(m, 2);
}
else
{
sum=recursion(m, n-1)*recursion(m, 1);
}
}
return sum;
}
补充:软件开发 , C语言 ,