Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <string>
- using namespace std;
- int main() {
- int n;
- cin >> n;
- double a;
- double oddmin = 10000.0, oddmax = -10000.0, oddsum = 0, evenmin = 10000.0, evenmax = -10000.0, evensum = 0;
- bool haseven = false, hasodd = false;
- if (n > 0) {
- for (int i = 1; i <= n; i++)
- {
- cin >> a;
- if (i % 2 == 0)
- {
- if (a<evenmin) {
- evenmin = a;
- }
- if (a>evenmax)
- {
- evenmax = a;
- }
- evensum += a;
- haseven = true;
- }
- else
- {
- if (a<oddmin) {
- oddmin = a;
- }
- if (a>oddmax)
- {
- oddmax = a;
- }
- oddsum += a;
- hasodd = true;
- }
- }
- }
- cout << "OddSum=" << oddsum << ", ";
- if (!hasodd) {
- cout << "OddMin=" << "No, ";
- cout << "OddMax=" << "No, ";
- }
- else
- {
- cout << "OddMin=" << oddmin << ", ";
- cout << "OddMax=" << oddmax << ", ";
- }
- cout << "EvenSum=" << evensum << ", ";
- if (!haseven) {
- cout << "EvenMin=" << "No, ";
- cout << "EvenMax=" << "No";
- }
- else
- {
- cout << "EvenMin=" << evenmin << ", ";
- cout << "EvenMax=" << evenmax << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement