• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# odd/even - sum, min, max

JOHNYTHEWINNER Feb 2nd, 2020 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. # include <iostream>
2. using namespace std;
3. #include <iomanip>
4. #include <math.h>
5. #include <cmath>
6. #include <string>
7. int main()
8. {
9.     int n;
10.     cin >> n;
11.     double temp;
12.     double oddsum = 0;
13.     double evensum = 0;
14.     double oddmax = INT_MIN;
15.     double evenmax = INT_MIN;
16.     double oddmin = INT_MAX;
17.     double evenmin = INT_MAX;
18.     for (int i = 1; i <= n; i++)
19.     {
20.         cin >> temp;
21.         if (i % 2 == 0) {
22.             if (evenmax <= temp)
23.             {
24.                 evenmax = temp;
25.             }
26.             if (evenmin >= temp)
27.             {
28.                 evenmin = temp;
29.             }
30.             evensum += temp;
31.         }
32.         if (i % 2 != 0) {
33.             if (oddmax <= temp)
34.             {
35.                 oddmax = temp;
36.             }
37.             if (oddmin >= temp)
38.             {
39.                 oddmin = temp;
40.             }
41.             oddsum += temp;
42.         }
43.
44.     }
45.     cout << "OddSum=" << fixed << setprecision(2) << double(oddsum) <<"," << endl;
46.     if (oddmin != INT_MAX) {
47.         cout << "OddMin=" << fixed << setprecision(2) << double(oddmin) << "," << endl;
48.     }
49.     else {
50.         cout << "OddMin=No," << endl;
51.     }
52.     if (oddmax != INT_MIN) {
53.         cout << "OddMax=" << fixed << setprecision(2) << double(oddmax) << "," << endl;
54.     }
55.     else {
56.         cout << "OddMax=No," << endl;
57.     }
58.     cout << "EvenSum=" << fixed << setprecision(2) << double(evensum) << "," << endl;
59.
60.     if (evenmin != INT_MAX) {
61.         cout << "EvenMin=" << fixed << setprecision(2) << double(evenmin) << "," << endl;
62.     }
63.     else {
64.         cout << "EvenMin=No," << endl;
65.     }
66.     if (evenmax != INT_MIN) {
67.         cout << "EvenMax=" << fixed << setprecision(2) << double(evenmax) << endl;
68.     }
69.     else {
70.         cout << "EvenMax=No" << endl;
71.     }
72.
73.
74.
75.     return 0;
76. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Top