中国大学MOOC:分析下面程序实现的功能intfunc(intdata){intcount=0;while(data!=0){data&=data-1;count++;}returncount;}
举一反三
- 分析下面程序实现的功能intfunc(intdata){in...unt++;}returncount;}
- 下面程序输入12345,输出结果是()#include#includeintmain(){intdata;scanf("%d",&data);While(data){printf("%d",data%10);data=data/10;}} A: 1234 B: 54321 C: 12345 D: 5432
- 有如下程序 #include intchange(int*data) { *data=*data%2; return(*data)+1; } main() { intdata=12; change(&data); printf("%d,",data); data=change(&data); printf("%d,",data); } 程序运行后的输出结果是()
- 写出下面程序的输出结果 publicclassTestjava{ publicstaticvoidmain(String[]args){ Stringstr="abbaefabbewbvwabbswgfga"; System.out.println("count="+getSubCount(str,"abb")); } publicstaticintgetSubCount(Stringstr,Stringkey){ intcount=0; intindex=0; while((index=str.indexOf(key,index))!=-1){ System.out.println("index="+index); index=index+key.length(); count++; } returncount; } }
- 下面程序输入12345,输出结果是() #include #include int main() { int data; scanf("%d",&data); While(data) {printf("%d",data%10); data=data/10; } }