Skip to content

Instantly share code, notes, and snippets.

@acyuta
Last active October 29, 2015 17:46
Show Gist options
  • Save acyuta/03751c06ea061f5e4554 to your computer and use it in GitHub Desktop.
Save acyuta/03751c06ea061f5e4554 to your computer and use it in GitHub Desktop.
For T
#include <iostream>
#include <limits>
// climits for intmax value
using namespace std;
void print_array(int *a, int size) {
for (int i = 0; i < size; i++)
cout << a[i] << ' ';
cout << endl;
}
int main() {
int n = -1;
cout << "Input array length: ";
cin >> n;
int MAX = numeric_limits<int>::max();
int MIN = numeric_limits<int>::min();
if (n <= 0 || n >= MAX) {
cerr << "Invalid value. Input value from 1 to " << MAX << endl;
return 1;
} else {
int a[n];
cout << "Enter array values, please: ";
for (int i = 0; i < n; i++) {
cin >> a[i];
}
//reading ended;
int multiple = 1;
int sum = MIN;
int current_sum = 0;
bool sum_action = false;
for (int i = 0; i < n; i++) {
if (a[i] % 2 == 0) multiple *= i + 1;
if (sum_action) {
if (a[i] == 0) {
if (sum == MIN)
sum = 0;
sum += current_sum;
current_sum = 0;
} else {
current_sum += a[i];
}
}
if (!sum_action && a[i] == 0) {
sum_action = true;
}
} //end for
// reverse array
for (int i = 0; i < n / 2; i++) {
int temp = a[i];
a[i] = a[n - i - 1];
a[n - i - 1] = temp;
}
cout << "Multiple indexes value = " << multiple << endl << "Sum between zeros = ";
if (sum == MIN)
cout << "unknown" << endl;
else
cout << sum << endl;
cout << "Inversed array: ";
for (int i = 0; i < n; i++) {
cout << a[i] << ' ';
}
cout << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment