Advertisement
fferum

Untitled

Apr 20th, 2020
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.98 KB | None | 0 0
  1. /*
  2. Author: Филипповых Матвей
  3. Group: СБС-901
  4. вариант: 3.5
  5. Description: Задан массив действительных чисел из 10 элементов и некоторое пороговое значение bound_value.
  6. Парой будем считать два элемента, которые равноудалены от начала и конца массива (первый элемент образует пару с последним, второй — с предпоследним и так далее).
  7. Найти все пары, среднее значение которых выше порогового значения. Вывести на консоль значения найденных элементов вместе с индексами.
  8. */
  9. #include<locale.h>
  10. #include <ctime>
  11. #include <cstdio>
  12. #include<stdlib.h>
  13. #include<cstdlib>
  14. #include<iostream>
  15. using namespace std;
  16. float random(const float a, const float b)
  17. {
  18.     float rnd_0_1 = float(rand() / RAND_MAX);
  19.     return a + (b - a) * rnd_0_1;
  20. }
  21.  
  22. float average(float the_first_value, float second_value)
  23. {
  24.     float average;
  25.     average = (the_first_value + second_value) / 2;
  26.     return average;      
  27. }
  28. int main() {
  29.     setlocale(LC_ALL, "Russian");
  30.     srand(time(nullptr));
  31.     int the_length_of_the_array = 10;
  32.     float data_array[10];
  33.     int counter = 0;
  34.     float the_first_value;
  35.     float second_value;
  36.     int index_of_the_second;
  37.     float bound_value;
  38.     int answer=0;
  39.     srand(time(NULL));
  40.     printf("Хотите сами вести числа в массив? если да напишите \"1\"");
  41.     scanf_s("%d", &answer);
  42.     if (answer == 1) {
  43.         for (counter = 0; counter < the_length_of_the_array; ++counter) {
  44.             scanf_s("%f", &data_array[counter]);
  45.         }
  46.        
  47.     }
  48.     else {
  49.         srand(10);
  50.         for (counter = 0; counter < the_length_of_the_array; ++counter) {
  51.             data_array[counter]= random(-1000,1000);
  52.             printf("%f ", &data_array[counter]);
  53.         }
  54.        
  55.     }
  56.     answer = 0;
  57.     printf("Хотите сами вести числа bound_value? если да напишите \"1\"");
  58.     scanf_s("%d", &answer);
  59.     if (answer == 1) {
  60.         scanf_s("\nbound_value=%f", &bound_value);
  61.         printf("bound_value=%f", &bound_value);
  62.     }
  63.     else {
  64.         srand(1);
  65.         bound_value = random(-1000, 1000);
  66.         printf("bound_value=%f ", bound_value);
  67.        
  68.     }
  69.     for (counter = 0; counter < the_length_of_the_array/2; ++counter) {
  70.         index_of_the_second = the_length_of_the_array -1- counter;
  71.         the_first_value = data_array[counter];
  72.         second_value = data_array[index_of_the_second];
  73.         if (average(the_first_value, second_value) > bound_value) {
  74.             printf("\n индекс первого числа в паре=%d\n", counter+1);
  75.             printf(" значение первого числа в паре=%f\n", data_array[counter]);
  76.             printf("\n индекс второго числа в паре=%d\n", index_of_the_second+1);
  77.             printf(" значени первого числа в паре=%f\n\n\n", data_array[index_of_the_second]);
  78.         }
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement