例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语句先循环再判断

posted on 2019-04-06 09:31  凯*凯  阅读(146)  评论(0编辑  收藏  举报

导航