a) 判断它是几位数
b) 请将它正序输出,并且每位之间插入一个*号(例如:输入123,输出1*2*3)
谢谢各位了!!!
#include <stdio.h>
#include <math.h>
unsigned int Pow(int n);
int main(void){
int i,b;
printf("input value\n");
scanf("%d",&i);
b=(unsigned int)(1+log10(abs(i)));
printf("The number has %d bit!\n",b);
while(b!=0){
printf("%d*",i/Pow(b-1));
i=i%Pow(b-1);
b--;
}
return 0;
}
unsigned int Pow(int n){
int i,m=1;
for(i=0;i<n;i++)
#include <stdio.h>
#include <math.h>
unsigned int Pow(int n);
int main(void){
int i,b;
printf("input value\n");
scanf("%d",&i);
b=(unsigned int)(1+log10(abs(i)));
printf("The number has %d bit!\n",b);
while(b!=0){
printf("%d*",i/Pow(b-1));
i=i%Pow(b-1);
b--;
}
return 0;
}
unsigned int Pow(int n){
int i,m=1;
for(i=0;i<n;i++)
m*=10;
return m;
}
这个改法好一点。
#include <stdio.h>
#include <math.h>
unsigned int Pow(int n);
int main(void){
int i,b,j=0;
printf("input value\n");
scanf("%d",&i);
b=(unsigned int)(1+log10(abs(i)));
printf("The number has %d bit!\n",b);
while(b!=0){
(j==0)?printf("%d",i/Pow(b-1)):printf("*%d",i/Pow(b-1)); /*int Pow(int n) 1)是自定义函数,2)调用十几次方*/
i=i%Pow(b-1);
j++;
b--;
}
getch();
return 0;
}
unsigned int Pow(int n){
int i,m=1;
for(i=0;i<n;i++)
m*=10;
return m;
}
[此贴子已经被作者于2006-11-9 15:15:49编辑过]