fork download
  1. /*Write a program to take an input array of size n. The array should contain all the integers between 0 to n
  2. except for one. Print that missing number*/
  3. #include <stdio.h>
  4.  
  5. int main() {
  6. int n;
  7. scanf("%d", &n);
  8.  
  9. int arr[n];
  10. int sum = 0;
  11.  
  12. for (int i = 0; i < n; i++) {
  13. scanf("%d", &arr[i]);
  14. sum += arr[i];
  15. }
  16.  
  17. int total = n * (n + 1) / 2; // sum of 0 to n
  18. int missing = total - sum;
  19.  
  20. printf("%d", missing);
  21. return 0;
  22. }
  23.  
  24.  
  25.  
Success #stdin #stdout 0.01s 5320KB
stdin
5
0 1 2 4 5
stdout
3