C语言函数问题求解答，求大神

#include
#include
int fun(int x);
int main(void)
{
int m1,m2;
printf("Input m1: ");
scanf("%d",&m1);
printf("Input m2: ");
scanf("%d",&m2);
printf("%d's reverse is:%d ",m1,fun(m1));
printf("%d's reverse is:%d ",m2,fun(m2));
return 0;}

int fun(int x)
{
int count,i,d,p,sum=0;
p=x;
if (x>0){
do{ x=x/10;
count++;} while (x!=0);
for (i=1;i<=count;i++){
d=p%10;

``````sum=sum+p*pow(10,count-i);
p=p/10;}

return sum;}
if (x<0){
x=-x;
``````

do{ x=x/10;
count++;} while (x!=0);
for (i=1;i<=count;i++){
d=p%10;

``````sum=sum+p*pow(10,count-i);
p=p/10;}
return  -sum;
``````

}
}

6个回答

int fun(int x)
{
int flg,i,sum=0;
if (x>0){
x=-x;
flg=1;
}
do{ m=x%10;
x=x/10;
sum = sum * 10 + m;
} while (x!=0);
if (flg ==1) {
sum = -sum；
}
return sum;
}

sum=sum+p*pow(10,count-i);

return -sum;应改为return sum;因为此时p已经为负数，不需要再加负号
int fun(int x)
{
int count=0,i,d,p,sum=0;
p=x;
if (x>0)
{
do
{
x=x/10;
count++;
} while (x!=0);
for (i=1;i<=count;i++)
{
d=p%10;
sum=sum+d*pow(10,count-i);
p=p/10;
}
return sum;
}
if (x<0)
{
x=-x;
do
{
x=x/10;
count++;
} while (x!=0);
for (i=1;i<=count;i++)
{
d=p%10;
sum=sum+d*pow(10,count-i);
p=p/10;
}
return sum;
}
}