The number of C language falling into a trap (the answer system prompts me that I have a mistake)

for any natural number N0, first add the sum of its numbers, then multiply the sum by 3 and add 1 to become a new natural number N = 1, and then repeat this operation for N1 to produce a new natural number N2. Repeat this operation many times, and the result will be a fixed number Nk, which is like falling into a number "trap". This question requires that the natural number of input be given the process of falling into the "trap".

input format:
give a natural number N0 (N0 < 30000) on one line.
output format:
for input N"0, output the steps that fall into the trap line by line. Line I describes step I of N falling into a trap, in the format: iRV N falling i (i 1). When the result of the natural number obtained in a certain step Nk (k 1) is the same as the previous step Nk-1, stop the output.

my code is as follows:

-sharpinclude<stdio.h>
int xian=0;
int trap(int a){
    int wei=1,x,b,sum=0;
    x=a;
    while(x>9){
        x/=10;
        wei*=10;
    }
    do{
        b=a/wei;
        sum+=b;
        a%=wei;
        wei/=10;
    }while(wei>0);
    xian=sum*3+1;
    return xian;
}

int main(){
    int a,b=0,shu=1,c;
    int trap(int a);
    scanf("%d",&a);
    c=trap(a);
    printf("%d:%d\n",shu,c);
    while(b!=c){
        b=c;
        c=trap(xian);
        shuPP;
        printf("%d:%d\n",shu,xian);
    }
    return 0;
}
C
Apr.05,2021

when the input is 13 , just output

1:13

is about to stop. But your program output

1:13
2:13

ask for a solution. I really want to know why.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b30b28-2bd1c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b30b28-2bd1c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?