#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter size of array: ";
cin >> n;
int arr[n];
cout << "Enter " << n << " elements: ";
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int sumEven = 0, sumOdd = 0;
// Traverse array
for (int i = 0; i < n; i++) {
if (i % 2 == 0) {
sumEven += arr[i]; // even index
} else {
sumOdd += arr[i]; // odd index
}
}
int difference = sumEven - sumOdd;
cout << "Sum of even indices = " << sumEven << endl;
cout << "Sum of odd indices = " << sumOdd << endl;
cout << "Difference (even - odd) = " << difference << endl;
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: