字符串逆序和统计数据中有多少位是1

    技术2022-05-18  14

    void invert(char *str,int len){ int i,j,n,temp; n=(len-1)/2;  for(i=0;i<=n;i++) {  j=len-1-i;    temp=*(str+i);  *(str+i)=*(str+j);  *(str+j)=temp; } }

    int count(char *s,int len){ int i,j,cnt=0; for(j=0;j<len;j++) {  for(i=0;i<8;i++)  {   if((*s&1)==1)   {    cnt++;   }   *s=*s>>1;  }  s++; } printf("cnt=%d /n",cnt); return cnt;}

    int main(){ char array[]="happy life"; char b[10]={3,3,3,11,1,1,1,1,1,1}; int  countvalue=0;  countvalue=count(b,sizeof(b)); invert(array,sizeof(array));

    }


    最新回复(0)