FindMaxElemOfArray. C Tutorials. Embarcadero Rad Studio IDE. Simple Input/Output. Arrays. Algorithms. Console application. The console application project is written in C++ using the Embarcadero Rad Studio integrated development environment. It features simple input/output. It also handles arrays and random numbers. Finding the maximum element in an array is also possible. The program does the following:
- Prompts the user for the number of elements in the array.
- Allocates memory and creates an array of integers with the number of elements entered previously.
- Fills the created array with random positive integers from 1 to 100.
- Displays the received elements on the screen in a space-separated string in a loop with a parameter from 0 to the number of array elements - 1. (array numbering starts from 0).
- Creates two temporary variables for the index of the maximum element of the array and its value.
- The first variable is assigned the value 0, and the second is assigned the value of the element with the number (index) 0 (array numbering starts with 0).
- In the second loop with a parameter from 1 to the number of array elements - 1, the search for the maximum array element and its index (number) occurs. If the next element is greater than the previously found one, then its number (index) and value are remembered. After the loop completes, the index and element value variables will contain the maximum of the array.
- Displays the index of the maximum element of the array and its value.
FindMaxElemOfArray. Занятия по C. ИС Embarcadero Rad Studio. Простой Ввод-вывод. Массивы. Алгоритмы. Консольное приложение. Проект консольного приложения написан на языке программирования C в интегрированной среде Embarcadero Rad Studio. Простой ввод-вывод. Работа с массивами и случайными числами. Поиск максимального элемента массива. Программа делает следующее:
- Запрашивает у пользователя количество элементов массива.
- Выделяет память и создаёт массив целых чисел с количеством элементов введённым ранее.
- Заполняет созданный массив случайными целыми положительными числами от 1 до 100.
- Выводит на экран полученные элементы в строку через пробел в цикле с параметром от 0 до количества элементов массива - 1. (нумерация массива начинается с 0).
- Создаёт две временные переменные для индекса максимального элемента массива и его значения.
- Первой переменной присваивается значение 0 , а второй - значение элемента с номером (индексом) 0 (нумерация массива начинается с 0).
- Во втором цикле с параметром от 1 до количества элементов массива - 1 происходит поиск максимального элемента массива и его индекса (номера). Если очередной элемент больше ранее найденного, то запоминается его номер (индекс) и значение. После завершения работы цикла в переменных индекса и значения элемента будет содержаться максимум массива
- Выводит на экран индекс максимального элемента массива и его значение.