数字反转

前提条件

  1. 熟悉if-else语句
  2. 熟悉while循环
  3. 熟悉C运算符

数字反转,例如:
132 = 231
123 = 321

代码

#include<stdio.h>

int main()
{

    unsigned long int numb,numb_temp,revrseNum=0;
    unsigned long int r;

    printf("请输入一个数: ");
    scanf("%ld",&numb);

    numb_temp=numb;

    while(numb_temp>0)   /*132 = 2 ----> 2*10+3=23------>23*10+1=231*/
    {
        r=numb_temp%10;
        revrseNum=(revrseNum*10)+r;
        numb_temp=numb_temp/10;
    }

    printf("\n%ld反转后为%ld",numb,revrseNum);

    return 0;
}