Problem Link: Missing Number
Approach
The expected sum of is . Subtract the given sum to find the missing number.
Solution
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, s = 0, x; cin >> n;
for (int i = 0; i < n - 1; i++) { cin >> x; s += x; }
cout << n * (n + 1) / 2 - s;
}