Only one number appears once in a set of data. All other numbers appear in pairs. Please find out the number.

Source: Internet
Author: User

#include <stdio.h> #include <stdlib.h>int find_f (int arr[], int len)        //looking for individual number { int i, j, k; for  (i = 0; i  < len; i++)  {  k = 0;  for  (j = 0; j  < len; j++)   {   if  ((Arr[i] & arr[j])  ==  Arr[i])    //If the two numbers are the same,k++    k++;                              }  if  (k == 1)  return  (i);         //   if (k=1), which is the only one in this array, returns the subscript  } return  (len + 1) of this number;} Int main () { int arr[] = { 4, 6, 4, 5, 5, 3, 6  };    //array initialization, freely assignable  int len = sizeof (arr)  / sizeof (arr[0]),c;      //array length  c = find_f (arr, len);         / /function call  if  (C > len)               //determines whether the return value is legitimate   printf ("there is no separate number in this set of numbers \ n");  else  printf ("%d\n", Arr[c]);         //is legally the output of a separate number  system ("pause");  return 0;}

This article is only in the learning process of their own ideas, can only achieve simple functions, may not consider the optimization of the program, and the code written by the great God there is a certain gap, if the great God found the problem, please enlighten me, if you have a better way, may wish to share, thank you!


This article is from the "Sharing Progress" blog, be sure to keep this source http://xmwen1.blog.51cto.com/10730069/1706070

Only one number appears once in a set of data. All other numbers appear in pairs. Please find out the number.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.