c语言问题: 谁能帮我解释一下下面的程序是完成什么任务的、?谢谢了
#include<stdio.h>intmystery(unsignedbits);/*prototype*/intmain(void){unsignedx;/*xwil...
#include <stdio.h>
int mystery( unsigned bits ); /* prototype */
int main( void )
{
unsigned x; /* x will hold an integer entered by the user */
printf( "Enter an integer: " );
scanf( "%u", &x );
printf( "The result is %d\n", mystery( x ) );
return 0; /* indicates successful termination */
} /* end main */
/* What does this function do? */
int mystery( unsigned bits )
{
unsigned i; /* counter */
unsigned mask = 1 << 31; /* initialize mask */
unsigned total = 0; /* initialize total */
for ( i = 1; i <= 32; i++, bits <<= 1 ) {
if ( ( bits & mask ) == mask ) {
total++;
} /* end if */
} /* end for */
return !( total % 2 ) ? 1 : 0;
} /* end function mystery */ 展开
int mystery( unsigned bits ); /* prototype */
int main( void )
{
unsigned x; /* x will hold an integer entered by the user */
printf( "Enter an integer: " );
scanf( "%u", &x );
printf( "The result is %d\n", mystery( x ) );
return 0; /* indicates successful termination */
} /* end main */
/* What does this function do? */
int mystery( unsigned bits )
{
unsigned i; /* counter */
unsigned mask = 1 << 31; /* initialize mask */
unsigned total = 0; /* initialize total */
for ( i = 1; i <= 32; i++, bits <<= 1 ) {
if ( ( bits & mask ) == mask ) {
total++;
} /* end if */
} /* end for */
return !( total % 2 ) ? 1 : 0;
} /* end function mystery */ 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询