Pow能与整型一起用吗?
输入一个不多于5位数的数,输出他的位数、每位数的数字,例如输入1234 输出 4 1 2 3 4但编译时出现:[Warning] converting to `int' from `double'
invalid operands of types `double' and `int' to binary `operator%'
的警告,也不知道为啥
#include<iostream.h>
#include<math.h>
int main()
{
int n;
while(cin>>n)
{
int k=1,a,b,c,d,e;
if((n-10)>0)
k++;
if((n-100)>0)
k++;
if((n-1000)>0)
k++;
if((n-10000)>0)
k++;
cout<<"this is a"<<" "<<k<<" "<<"digits"<<endl;
a=n/pow(10,k);
b=n/pow(10,k-1)%10;
c=n/pow(10,k-2)%10;
d=n/pow(10,k-3)%10;
d=n%10;
cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<" "<<endl;
}
}