一串数字相乘 求积末尾的零的个数
该串数字以0结尾,其余为大于0小于1000的整数
#include
int main()
{
int x;
int num2=0,num5=0;
do
{
scanf("%d",&x);
while(1)
{
if(x%2==0)
{
num2++;
x/=2;
}
else if(x%5==0)
{
num5++;
x/=5;
}
else
break;
}
}
while(x!=0);
printf("%d",num2<num5?num2:num5);
}
你的代码之前死循环了,输入x=0,模2,模5都是0,就在那里一直循环
#include<stdio.h>
int main()
{
int x;
int num2 = 0, num5 = 0;
while(1){
scanf("%d", &x);
if (x == 0)
break;
while (x % 2 == 0) {
num2++;
x /= 2;
}
while (x % 5 == 0) {
num5++;
x /= 5;
}
}
printf("%d", num2 < num5 ? num2 : num5);
return 0;
}