• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

Mart94 Oct 7th, 2014 175 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <iostream>
2. #include <cmath>
3. using namespace std;
4.
5. int main() {
6.     int elements;
7.     int len;
8.
9.     cout << "Elemente kokku: ";
10.     cin >> elements;
11.
12.     len = elements-1;
13.
14.     double array1[len], array2[len];
15.
16.     for(int i = 0; i < elements; i++) {
17.         cout << "Sisesta jada " << i+1 << ". number: ";
18.         cin >> array1[i];
19.     }
20.
21.     double result;
22.
23.     for(int i = 0; i < elements; i++) {
24.             result += array1[i];
25.     }
26.
27.     double average = result/elements;
28.
29.     cout << "A) Aritmeetiline keskmine: " << average << endl;
30.
31.     // B ülesanne
32.
33.     for(int i = 0; i < elements; i++) {
34.             if(array1[i] < average) {
35.                     // Väiksem
36.                     array2[i] = -1;
37.             } else if(array1[i] == average) {
38.                    // Võrdne
39.                     array2[i] = 0;
40.             } else if(array1[i] > average) {
41.                    // Suurem
42.                     array2[i] = 1;
43.             }
44.     }
45.
46.     cout << "B) Uus jada: ";
47.
48.     for(int i = 0; i < elements; i++) {
49.             cout << array2[i];
50.     }
51.
52.     cout << endl;
53.
54.     system("PAUSE");
55.     return EXIT_SUCCESS;
56. }
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.
Not a member of Pastebin yet?