例4-9 逆序输出数字

例4-9 逆序输出数字

输入一个正整数,将其逆序输出
程序核心——while语句

程序


#include<stdio.h>
int main()
{
    int x;
    
    printf("Enter x:");
    scanf("%d",&x);
    while(x!=0)
    {
        printf("%d ",x%10);
        x/=10;
    }
}

结果

Enter x:987654321
1 2 3 4 5 6 7 8 9
--------------------------------
Process exited after 5.401 seconds with return value 0
请按任意键继续. . .

分析

重点:while语句先循环再判断

猜你喜欢

转载自www.cnblogs.com/5236288kai/p/10660841.html
今日推荐