SumOfElems. C Tutorials. Microsoft Visual Studio IDE. Simple Input/Output. Arrays. Algorithms. Console application. A console application in the C programming language. The program does the following:
- Asks the user to enter the number of elements in the array.
- Allocates memory and creates a dynamic array with the number of elements entered previously.
- A variable for sum of elements of the array is defined. It's value is 0.
- The first loop with the parameter is executed. 4.1. The initial value of the parameter is set to 1, and the final value is set to the number of array elements. 4.2. A series of loops are executed, where the array elements are filled by random integer values from 1 to 50. 4.3. The value of the loop parameter is compared with the final value. If it is less, the loop continues. Otherwise, it terminates. 4.4. The loop parameter variable is incremented by the loop increment. In this example, it is 1.
- The second loop with the parameter is executed. 5.1. The initial value of the parameter is set to 1, and the final value is set to the number of array elements. 5.2. A series of loops are executed, where the array elements are displayed on the screen in a space-separated string. 5.3 In this same loop, the sum of the array elements is calculated. The value of the array element that was printed earlier is added to the sum variable of the array elements. 5.4. The value of the loop parameter is compared with the final value. If it is less, the loop continues. Otherwise, it terminates. 5.5. The loop parameter variable is incremented by the loop step. In this example, it is 1.
- The number of array elements and their sum are displayed on the screen. Developed in the Microsoft Visual Studio integrated environment.
SumOfElems. ИС Visual Studio. Занятия по C. Простой Ввод/Вывод. Алгоритмы. Массивы. Платформа Windows. Консольное приложение. Консольное приложение написанное на языке программирования C. Программа делает следующее:
- Просит пользователя ввести количество элементов в массиве.
- Выделяет память и создаёт динамический массив с количеством элементов введённым ранее.
- Вводится переменная для суммы элементов массива. Её значение равно 0.
- Выполняется первый цикл с параметром. 4.1. Начальное значение параметра устанавливается равным 1, а конечное - числу элементов массива. 4.2. Выполняется серия цикла, где заполняются элементы массива целыми случайными числами от 1 до 50. 4.3. Значение параметра цикла сравнивается с конечным. Если оно меньше цикл выполняется. В противном случае - завершается. 4.4. Переменная параметра цикла увеличивается на шаг цикла. В данном примере он равен 1.
- Выполняется второй цикл с параметром. 5.1. Начальное значение параметра уставливается равным 1, а конечное - числу элементов массива. 5.2. Выполняется серия цикла, где выводятся элементы массива на экран в строку через пробел. 5.3 В этой же серии цикла считается сумма элементов массива. К переменной суммы элементов массива прибавляется значение элемента массива, который был выведен ранее 5.4. Значение параметра цикла сравнивается с конечным. Если оно меньше цикл выполняется. В противном случае - завершается. 5.5. Переменная параметра цикла увеличивается на шаг цикла. В данном примере он равен 1.
- На экран выводится количество элементов массива и их сумма. Разработано в интегрированной среде Microsoft Visual Studio.