Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Author: Филипповых Матвей
- Group: СБС-901
- вариант: 3.5
- Description: Задан массив действительных чисел из 10 элементов и некоторое пороговое значение bound_value.
- Парой будем считать два элемента, которые равноудалены от начала и конца массива (первый элемент образует пару с последним, второй — с предпоследним и так далее).
- Найти все пары, среднее значение которых выше порогового значения. Вывести на консоль значения найденных элементов вместе с индексами.
- */
- #include<locale.h>
- #include <ctime>
- #include <cstdio>
- #include<stdlib.h>
- #include<cstdlib>
- #include<iostream>
- using namespace std;
- float average(float the_first_value, float second_value)
- {
- float average;
- average = (the_first_value + second_value) / 2;
- return average;
- }
- int main() {
- setlocale(LC_ALL, "Russian");
- int the_length_of_the_array = 10;
- float data_array[10];
- int counter = 0;
- float the_first_value;
- float second_value;
- int index_of_the_second;
- float bound_value;
- int answer=0;
- srand(time(NULL));
- printf("Хотите сами вести числа в массив? если да напишите \"1\"");
- scanf_s("%d", &answer);
- if (answer == 1) {
- for (counter = 0; counter < the_length_of_the_array; ++counter) {
- scanf_s("%f", &data_array[counter]);
- }
- }
- else {
- srand(10);
- for (counter = 0; counter < the_length_of_the_array; ++counter) {
- data_array[counter]= (float)(rand()) / RAND_MAX;
- printf("%f ", &data_array[counter]);
- }
- }
- answer = 0;
- printf("Хотите сами вести числа bound_value? если да напишите \"1\"");
- scanf_s("%d", &answer);
- if (answer == 1) {
- scanf_s("\nbound_value=%f", &bound_value);
- printf("bound_value=%f", bound_value);
- }
- else {
- srand(1);
- bound_value = (float)(rand()) / RAND_MAX;
- printf("bound_value=%f ", bound_value);
- }
- for (counter = 0; counter < the_length_of_the_array/2; ++counter) {
- index_of_the_second = the_length_of_the_array -1- counter;
- the_first_value = data_array[counter];
- second_value = data_array[index_of_the_second];
- if (average(the_first_value, second_value) > bound_value) {
- printf("\n индекс первого числа в паре=%d\n", counter+1);
- printf(" значение первого числа в паре=%f\n", data_array[counter]);
- printf("\n индекс второго числа в паре=%d\n", index_of_the_second+1);
- printf(" значени первого числа в паре=%f\n\n\n", data_array[index_of_the_second]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement