求大佬帮我看看哪里有问题,感谢

P1307 [NOIP2011 普及组] 数字反转

GX003 @ 2022-12-06 14:38:56

#include <stdio.h>
int fanzhuan(int a)
{
    int n,k,i;
    while(a!=0)
    {
        n = a % 10;
        k = k * 10 + n;
        a /= 10 ;
    }
    printf("%d",k);
 } 
int main()
{
    int a;
    scanf("%d",&a);
    if (a>0)
        fanzhuan(a);
    else if (a<0)
    {
        printf("-");
        a = - a;
        fanzhuan(a);
    }
    else
        printf("0");
return 0;
}

请问这边哪里出错了,没全对


by 编码落寞 @ 2022-12-06 14:41:56

@GX003

 int n,k,i;

这里k要初始化为0


by xXkivenXx @ 2022-12-11 19:12:52

用if与while循环试试。


|