给出一个正整数,要求1.求该数的位数;2.正序输出每一位数字;3.倒序输出每一位数字。
#include<stdio.h>
#include<math.h>
//对正整数进行计数操作,统计时采用统计一位,丢弃最低位的计数方式
int Count(int n)
{
int count=0;
while(n)
{
n=n/10;
count++;
}
return count;
}
//对正整数进行正序打印,通过调用计数函数实现,采用打印最高位,舍弃最高位的打印方式
void Print(int n)
{
if(n==0) printf("0");
while(n)
{
int tmp=pow((double)10,Count(n)-1);
printf("%-3d",n/tmp);
n=n%tm