Advertisement
fferum

Untitled

Apr 20th, 2020
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.84 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 average(float the_first_value, float second_value)
  17. {
  18.     float average;
  19.     average = (the_first_value + second_value) / 2;
  20.     return average;      
  21. }
  22. int main() {
  23.     setlocale(LC_ALL, "Russian");
  24.     int the_length_of_the_array = 10;
  25.     float data_array[10];
  26.     int counter = 0;
  27.     float the_first_value;
  28.     float second_value;
  29.     int index_of_the_second;
  30.     float bound_value;
  31.     int answer=0;
  32.     srand(time(NULL));
  33.     printf("Хотите сами вести числа в массив? если да напишите \"1\"");
  34.     scanf_s("%d", &answer);
  35.     if (answer == 1) {
  36.         for (counter = 0; counter < the_length_of_the_array; ++counter) {
  37.             scanf_s("%f", &data_array[counter]);
  38.         }
  39.        
  40.     }
  41.     else {
  42.         srand(10);
  43.         for (counter = 0; counter < the_length_of_the_array; ++counter) {
  44.             data_array[counter]= (float)(rand()) / RAND_MAX;
  45.             printf("%f ", &data_array[counter]);
  46.         }
  47.        
  48.     }
  49.     answer = 0;
  50.     printf("Хотите сами вести числа bound_value? если да напишите \"1\"");
  51.     scanf_s("%d", &answer);
  52.     if (answer == 1) {
  53.         scanf_s("\nbound_value=%f", &bound_value);
  54.         printf("bound_value=%f", bound_value);
  55.     }
  56.     else {
  57.         srand(1);
  58.         bound_value = (float)(rand()) / RAND_MAX;
  59.         printf("bound_value=%f ", bound_value);
  60.        
  61.     }
  62.     for (counter = 0; counter < the_length_of_the_array/2; ++counter) {
  63.         index_of_the_second = the_length_of_the_array -1- counter;
  64.         the_first_value = data_array[counter];
  65.         second_value = data_array[index_of_the_second];
  66.         if (average(the_first_value, second_value) > bound_value) {
  67.             printf("\n индекс первого числа в паре=%d\n", counter+1);
  68.             printf(" значение первого числа в паре=%f\n", data_array[counter]);
  69.             printf("\n индекс второго числа в паре=%d\n", index_of_the_second+1);
  70.             printf(" значени первого числа в паре=%f\n\n\n", data_array[index_of_the_second]);
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement