#include <stdio.h>
int calculate(int,int,int,int);
int myPow(int ,int);
int main()
{
int res;
res=calculate(1,3,0,calculate(6,1,0,1)+calculate(1,5,0,1));
printf("%d--%d\n",res);
sleep(5000);
return 0;
}
int calculate(int a,int b,int i,int n)
{
int res;
if(a>b)
{
res=a*myPow(10,i)*n;
res+=calculate(a-1,b,i+1,n);
return res;
}
else if(a<b)
{
res=a*myPow(10,i)*n;
res+=calculate(a+1,b,i+1,n);
return res;
}
else return a*myPow(10,i)*n;
}
int myPow(int x,int y)
{
if(y==0)return 1;
if(y<0)return 0;
int i,tempx=x,tempy=y;
while(tempy>1)
{
tempx*=x;
tempy--;
}
return tempx;
}
是要这样吗 |