fork download
  1. /******************************************************************************
  2.  
  3. Welcome to GDB Online.
  4. GDB online is an online compiler and debugger tool for C/C++.
  5. Code, Compile, Run and Debug online from anywhere in world.
  6.  
  7. *******************************************************************************/
  8.  
  9.  
  10. int singleNumber(int nums[], int size) {
  11. int result = 0;
  12. for (int i = 0; i < size; i++) {
  13. result ^= nums[i];
  14. }
  15. return result;
  16. }
  17.  
  18. int main() {
  19. int n;
  20.  
  21.  
  22. printf("Enter number of elements: ");
  23. scanf("%d", &n);
  24.  
  25. int arr[n];
  26.  
  27. printf("Enter %d elements:\n", n);
  28. for (int i = 0; i < n; i++) {
  29. scanf("%d", &arr[i]);
  30. }
  31.  
  32.  
  33. int unique = singleNumber(arr, n);
  34. printf("The element that appears only once is: %d\n", unique);
  35.  
  36. return 0;
  37. }
  38.  
  39.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Enter number of elements: Enter 0 elements:
The element that appears only once is: 0