问题九十六:Binary Numbers
[plain] #include <stdio.h>
#include <string.h>
int main()
{
int n;
int num;
int count;
int flag;
scanf("%d", &n);
while(n--)
{
count= flag=0;
scanf("%d", &num);
while(num)
{
if(num%2==1)
{
if(flag)
{
printf(" ");
}
printf("%d", count);
flag=1;
}
count++;
num/=2;
}
if(n>0)
{
printf("\n");
}
}
return 0;
}
#include <stdio.h>
#include <string.h>
int main()
{
int n;
int num;
int count;
int flag;
scanf("%d", &n);
while(n--)
{
count= flag=0;
scanf("%d", &num);
while(num)
{
if(num%2==1)
{
if(flag)
{
printf(" ");
}
printf("%d", count);
flag=1;
}
count++;
num/=2;
}
if(n>0)
{
printf("\n");
}
}
return 0;
}
补充:软件开发 , C语言 ,