Find missing element in the series.
Here is the code :
Thanks
#include <iostream> #include <conio.h> using namespace std; void main() { int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20 }; int result = 0; int numberOfElements = 20; int sum = (numberOfElements * (numberOfElements + 1)) / 2; int indivisualSum = 0; for (int index = 0; index < numberOfElements - 1; ++index) { indivisualSum += arr[index]; } cout << sum - indivisualSum; _getch(); }
Thanks
Comments
Post a Comment