小数数位顺序表

来源:百度知道 编辑:UC知道 时间:2024/07/08 01:48:26
ji !!!!~~~~~`

#include <stdio.h>
#include <math.h>
void main()
{
float num;
int temp0;
float temp1;
int r0[16],r1[16];
int i=0,j=1,m,n;
printf("Please input a decimal value:\n");
scanf("%f",&num);
temp0=num;
temp1=num-temp0;
while(temp0!=0)
{
r0[i]=temp0%10;
temp0=temp0/10;
i++;
}
while(temp1!=0)
{
r1[j]=temp1*10;
temp1=temp1*10;
temp1=temp1-r1[j];
j++;
}
printf("See the result:\n");
for(m=i-1;m>=0;m--)
printf("%d*%d\n",r0[m],(int)pow(10,m));
for(n=1;n<j;n++)
printf("%d*%g\n",r1[n],pow(0.1,n));
}

小数点右面依次为:十分位 百分位 千分位 万分位......
计数单位是:十分之一 百分之一 千分之一 万分之一......