Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main() {
- int elements;
- int len;
- cout << "Elemente kokku: ";
- cin >> elements;
- len = elements-1;
- double array1[len], array2[len];
- for(int i = 0; i < elements; i++) {
- cout << "Sisesta jada " << i+1 << ". number: ";
- cin >> array1[i];
- }
- double result;
- for(int i = 0; i < elements; i++) {
- result += array1[i];
- }
- double average = result/elements;
- cout << "A) Aritmeetiline keskmine: " << average << endl;
- // B ülesanne
- for(int i = 0; i < elements; i++) {
- if(array1[i] < average) {
- // Väiksem
- array2[i] = -1;
- } else if(array1[i] == average) {
- // Võrdne
- array2[i] = 0;
- } else if(array1[i] > average) {
- // Suurem
- array2[i] = 1;
- }
- }
- cout << "B) Uus jada: ";
- for(int i = 0; i < elements; i++) {
- cout << array2[i];
- }
- cout << endl;
- system("PAUSE");
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement