//program to give binary equivalent of a decimal number without using recurssion
#include<stdio.h>
#include<math.h>
int main(void)
{
int i=0,num,bin=0;
printf("enter number : ");
scanf("%d",&num);
while(num>0)
{
bin+=((float)(num%2))*pow(10.0,(float)i++);
num/=2;
}
printf("Binary equivalent is : %d",bin);
getchar();
return 0;
}
此代码不为7之类的输入提供所需的输出,但确实为某些数字提供了所需的输出。您可以帮我找出错误。