How to Fill an Array with Random Numbers and Find the Average in C++

Опубликовано: 04 Июль 2026
на канале: Real Programming Skool (RPS)
10
0

In this lesson, we write a C++ program that fills array elements with random numbers from 1 to 100, then finds and prints the average number of the array elements.

The user first enters how many elements she/he wants. After that, the program fills the array automatically with random values, displays the array elements, and returns the average of all numbers inside the array.

For example, if the user inputs:
5

The output can be:
Array Elements are: 77 88 38 30 99

The Average Number Of The Array is: 66.4

In this video, you will learn:
• How to fill an array with random numbers in C++
• How to ask the user for the number of array elements
• How to generate random numbers from 1 to 100
• How to store random values inside array elements
• How to display the array using DisplayArray()
• How to build a function to calculate the average of array elements
• How to reuse the sum function to get the average
• How to divide the total sum by the number of elements
• How to think like a programmer by extending an existing solution

This lesson is a very important beginner-friendly introduction to arrays, random number generation, and calculating averages in C++.

It also shows how re-usability and extendability work in programming, because we keep the previous functions and only add a new function for getting the average of the array elements.

If you are learning C++ problem solving step by step, this lesson will help you understand arrays, loops, functions, accumulation, division, and how to build larger solutions from smaller reusable parts.

This lesson 26 of Course 4: Problem Solving for Programmers Using C++ (Part 2) – Beginner Track.

▶ 🖥️ Start Here – Programming Roadmap & How to Learn Programming Step by Step:
   • Start Here – Programming Roadmap & How to ...  

▶ Join the Real Programming Skool community on Telegram:
http://t.me/RPSDiscussionChannel

#cplusplus #cpp #arrays #randomnumbers #programming #codingforbeginners #problemsolving #functions #loops #realprogrammingskool