fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int arr[] = {1, 2, 4, 5, 6}; // Example array with one number missing
  5. int n = 6; // The array should contain numbers from 1 to n → here n = 6
  6. int size = sizeof(arr) / sizeof(arr[0]);
  7.  
  8. printf("%d", size);
  9.  
  10. int total = n * (n + 1) / 2; // Sum of numbers from 1 to n
  11. int sum = 0;
  12.  
  13. for (int i = 0; i < size; i++) {
  14. sum += arr[i];
  15. }
  16.  
  17. int missingNumber = total - sum;
  18.  
  19. printf("The missing number is: %d\n", missingNumber);
  20.  
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
5The missing number is: 3