num[] array. Finally, to find the average of all array elements we divide sum by count. Divide the sum of array elements by number of elements to get the average of input numbers. Data Structure & Algorithm-Self Paced(C++/JAVA) Data Structures & Algorithms in Python; Data Science (Live) Full Stack Development with React & Node JS (Live) GATE CS 2023 Test Series; OS DBMS CN for SDE Interview Preparation; Explore More Self-Paced Courses; Programming Languages. Write a C++ Program For Average of 5 Numbers. sum= it will hold the float value for the sum of the array. In this article, you will learn how to find average of N numbers in the C language using for loop, array, functions, and while loop. The ( +) arithmetic operator is used to calculate the sum of two integers. Algorithm to Find Sum and Average of an Array Use the following algorithm to write a program to find sum and average of an array of numbers; as follows: Start Program Define array, avg, sum, i and n variables. Divide sum of all subjects by total number of subject to find average i.e. Learn C practically C Program Swap Numbers in Cyclic Order Using Call by Reference, Multiply two Matrices by Passing Matrix to a Function, Multiply Two Matrices Using Multi-dimensional Arrays. Data Structure & Algorithm-Self Paced(C++/JAVA) Data Structures & Algorithms in Python; Data Science (Live) Full Stack Development with React & Node JS (Live) GATE CS 2023 Test Series; OS DBMS CN for SDE Interview Preparation; Explore More Self-Paced Courses; Programming Languages. The function sumofarray () is the user defined function which calculates the sum of all array elements of an array. The C++ program is successfully compiled and run (on Codeblocks) on a Windows system. For any index i (0<= i <= N-1), add the value of element at index i to sum. Finally, the data entered by user is displayed. Ask user to enter number of elements 2. All rights reserved. Store it in some variables say eng, phy, chem, math and comp. Program: Calculate the average and percentage of student grade Laravel 8 Typeahead JS Autocomplete Search Example, Laravel 8 Try Catch in Controller Tutorial Example, Laravel 8 Send Email with PDF Attachment Tutorial, Laravel 8 Custom 404 500 Error Page Example, Laravel 8 Send Mail For Error Exceptions Tutorial With Example, How to Set Up File Permissions in Laravel 8, Laravel 8 Authentication with Breeze Tutorial Example, Laravel 8 Backup Store On Google Drive Example, Laravel 8 Backup Store On DropBOX Tutorial, Laravel 8 Convert PDF to Image Tutorial Example, Laravel 8 Get Country, City Name & Address From IP Address Example, Laravel 8 Send Emails using Office365 Example, Laravel 8 Create JSON File & Download From Text, Laravel 8 Download File From URL to Public Storage Folder, Laravel 8 Send SMS Notification to Mobile/ Phone Example, Laravel 8 Livewire Dependent Dropdown Tutorial, Laravel 8 Livewire Click Event Tutorial Example, Laravel 8 Livewire Select2 Dropdown Tutorial Example, Laravel 8 Send SMS to Mobile with Nexmo Example, Laravel 8 Find Nearest Location By Latitude and Longitude, Laravel 8 Generate and Read XML File Tutorial Example, Laravel 8 Botman Chatbot Tutorial Example, Laravel 8 Full Text Search using Ajax Example, Laravel Jetstream Customize Login with Username or Email Tutorial, Laravel Livewire Fullcalendar Integration Example, Laravel OneSignal Web Push Notification Example, Laravel Ajax Multiple Delete Records using Checkbox Example, Laravel 8 Add Share Social Media Button Example, Laravel Bootstrap 4 Multiselect Dropdown with Checkbox, Laravel 8 Automatic Daily Database Backup Example, Laravel Eloquent selectRaw Query Tutorial, How to Get Current User Location in Laravel 8, Laravel 8 Custom Email Verification System, Laravel 8 maddhatter/laravel-fullcalendar Tutorial with Example, Laravel 8 Generate PDF File using DomPDF Tutorial, Laravel 8 Resource Route Controller Example Tutorial, Laravel 8 Drag and Drop File/Image Upload using Dropzone JS, Laravel 8 Livewire Load More On Page Scroll Example, Laravel 8 Summernote Image Upload Tutorial, Auto Load More Data on Page Scroll in Laravel 8 with AJAX, Laravel 8 Datatables Filter Column Relationship Tutorial, Laravel 8 Custom Validation Error Messages Tutorial, Laravel 8 Google Autocomplete Address Tutorial, Laravel 8 CKeditor Image Upload Tutorial Example, Laravel 8 Push Notification to Android and IOS Tutorial, Laravel 8 Restrict User Access From IP Address, Laravel 8 Add Text Overlay Watermark on Image Example, Laravel Create Custom Facade Class Tutorial, Laravel 8 jQuery Ajax File Upload Progress Bar Example, Dynamic Dependent Dropdown In Laravel 8 Using jQuery Ajax, Laravel 8 Crop Image Before Upload using Cropper JS, Laravel 8 Cron Job Task Scheduling Tutorial, Laravel 8 Firebase Phone Number OTP Auth Example, Laravel 8 Dependent Country State City Dropdown with AJAX, Laravel 8 File Image Upload to AWS S3 Cloud Bucket, How to Send Email in Laravel 8 with Mailable and Mailtrap, Create admin user programmatically in WordPress, How To Integrate Google Recaptcha V3 In Laravel 8, Laravel 8 Vue JS File Upload Tutorial With Example, Difference Between Binary Search tree vs AVL tree, Difference Between Binary tree vs Binary Search tree, Difference Between Singly Linked List vs Doubly Linked List, Difference Between Stack and Array Data structure, Difference Between Tree and Graph Data structure, Difference Between Linear Queue and Circular Queue, Difference Between Array and Linked list In Data structure, Difference Between Stack and Queue In Data Structure, Difference Between Linear Search vs Binary Search, Difference Between Linear vs Non-Linear Data Structure, Program to check Twisted Prime Program in Java, Program to check Special Number Program in Java, Program to check Niven Number Program in Java, Program to check Happy Number Program in Java, Program to check CoPrime Numbers Program in Java, Program to check Circular Prime Program in Java, Prime Number Up to N Terms Program in Java, Program to check Amicable Numbers in Java, Program to check nth Prime Number In Java, Program to check Xylem and Phloem Number In Java, Program to check Krishnamurthy Number In Java, Program to check Autobiographical Number in Java, Program to check Fascinating Number in Java, Program to check Automorphic Number in Java, Program to check Palindrome Number In Java, Java Program to Find HCF and LCM of Two Numbers, Java Program to Find average of 3 numbers, Java Program to display odd numbers from 1 to n or 1 to 100, Java Program to display even numbers from 1 to n or 1 to 100, Java Program to display alternate prime numbers, Java Program to find largest of three numbers using ternary operator, Java Program to find smallest of three numbers using ternary operator, Java Program to swap two numbers using bitwise operator, Java Program to find Largest of three numbers, Java Program to check if a number is Positive or Negative, Java Program to print Armstrong numbers between a given range, Java Program to find square root of a number without sqrt method, Java Program to check if a given number is perfect square, Java program to break integer into digits, Java Program to display prime numbers between 1 and 100 or 1 and n, Java Program to display first 100 prime numbers, Java Program to Print Odd and Even Numbers from an array, Java Program to Remove Duplicate Element in an array, Java to Program Find Smallest Number in an array, Java Program to Find Largest Number in an array, Java Program to Find 2nd Largest Number in an array, Java Program to Find 3rd Largest Number in an array, Java Program to sort the elements of an array in descending order, Java Program to sort the elements of an array in ascending order, Java Program to right rotate the elements of an array, Java Program to print sum of all the items of the array, Java Program to print number of elements present in an array, Java Program to print smallest element in an array, Java Program to print largest element in an array, Java Program to print elements of an array present on odd position, Java Program to print elements of an array present on even position, Java Program to print elements of an array in reverse order, Java Program to print elements of an array, Java Program to print the duplicate elements of an array, Java Program to left rotate the elements of an array, Java Program to find the frequency of each element in the array, Java Program to copy all elements of one array into another array, Java Program to Add Two Matrix Using Multi-dimensional Arrays, Java Program to convert char Array to String, Java Program to Count Duplicate Elements in Array, Java Program to Add the elements of an Array, Java Program to Remove Element From Array, Java Program to Insert Element at Specific Position in Array, Java Program to find Sum of Two Arrays Elements, Java Program to Check if a word is present in sentence, Java program to count number of words in sentence, Java program to find Voting Age Program in Java, Java Program to check Equal Number in Java, Duplicate Words in String Program in Java, Increment Decrement Operators Program in Java, Java Program to Reverse a String using Recursion, Java Program to check Palindrome string using Recursion, Java Program to perform Arithmetic Operation using Method Overloading, Java Program to make a calculator using switch case, Java Program to find quotient and remainder, Java Program to calculate simple interest, Java Program to check whether input character is vowel or consonant, Java Program to Calculate Future Investment Value, Java Program to Calculate Batting Average, Java Program to Calculate Average Of N Numbers, Java Program to Generate Fibonacci Series using Recursion, Java Program to Find Sum of Digits Until Single Digit, Java Program to Find Sum of first & last digit of a number, Java Program to Find Sum of odd digits in a number, Java Program to Find sum of even digits in a number, Java Program to Find sum of N Natural numbers, Create Electric Bill Calculator Program In java, Create BMI (Body Mass Index) Calculator In Java, Java Program to Print 1 to 100 Without Loop, Java Program to Find Square Root of a Number, Java Program to Find Students Grades using Switch Case, Create Simple Mortgage Calculator In Java, Java Program to Find Distance Between 2 Points, Java Program to Calculate Average of 3 Numbers, Java Program to Calculate Average of Two Numbers, Python Program to Make a Flattened List from Nested List, Python Program to Create Pyramid Patterns, Python Program to Illustrate Different Set Operations, Python Program to Sort Words in Alphabetic Order, Python Program to Find Numbers Divisible by Another Number, Python Program to Find the Sum of Natural Numbers, Python Program to Find Armstrong Number in an Interval, Python Program to Print the Fibonacci sequence, Python Program to Find the Factorial of a Number, Python Program to Find the Largest Among Three Numbers, Python Program to Check if a Number is Odd or Even, Python Program to Check if a Number is Positive, Negative or 0, Python Program to Convert Kilometers to Miles, Python Program to Solve Quadratic Equation, Python Program to Calculate the Area of a Triangle, C Program to implement Shell sort Algorithm, C Program to implement Radix sort Algorithm, C Program to implement Bubble sort Algorithm, C Program to implement Selection sort Algorithm, C program to implement MERGE sort Algorithm, C Program to implement Insertion sort Algorithm, C Program to implement HEAP sort Algorithm, C Program to implement Bucket sort Algorithm, Structure of different types of sentences, Java Program to Convert Fahrenheit to Celsius, Java Program to Convert Celsius to Fahrenheit, Java Program to Convert Binary to HexaDecimal, Java Program to Calculate Average Using Arrays, Java Program to Check if An Array Contains a Given Value, Java Program to Find Largest and Smallest Number in an Array, Java Program to Sort Elements in Lexicographical Order, Java Program to Count the Number of Vowels and Consonants in a Sentence, Java Program to Find the Frequency of Character in a String, Java Program to Check Whether Given String is a Palindrome, Java Program to Calculate area of rectangle, Java Program to Calculate the Area of a Circle, Java Program to Make a Simple Calculator Using switch case, Java Program to Display Factors of a Number, Java Program to Check Whether a Number is Prime or Not, Java Program to Calculate the Sum of Natural Numbers, Java Program to Find all Roots of a Quadratic Equation, Java Program to Find the Largest Among Three Numbers, Java Program to Check Whether an Alphabet is Vowel or Consonant, Java Program to Generate Multiplication Table, Java Program to Swapping Two Numbers without Using a Temporary Variable, Java Program to Swapping Two Numbers Using a Temporary Variable, Java Program to Calculate Compound Interest, Java Program to Calculate Simple Interest, Java Program to Perform Addition, Subtraction, Multiplication and Division, Java Program to Count number of Digits In Number, Java Program to Check Whether a Number is Palindrome or Not, Java Program to Generate Fibonacci Series, Java Program to Print Table of any Number, Java Program to Find Factorial of a Number, Java Program to Check Whether a Number is Even or Odd, Java Program to Compute Quotient and Remainder, Java Program to Find ASCII Value of a character, Java Program to Multiply two Floating Point Numbers, Java Program to Get User Input and Print on Screen, How to Clear Cache in Laravel 8 with artisan commands, AngularJS User Registration Login Authentication Example, Simple User Registration Form Example in AngularJS. Array declaration and initialization Essential variable declaration loop for calculating total through each value Learn to code interactively with step-by-step guidance. Sum and Average Of Subjects. All Rights Reserved. The grading system will be applied as shown in the table given below: Here, the mark range is the average mark range. In this post, you will learn how to Calculate Average Using Arrays in C++ programming language. Then using a for loop, we find the sum of all array elements and store the result in sum variable. Take 5 numbers from the end-user and calculate the average value. The average of five numbers can be calculated as, In this example, you will learn to calculate the average of n number of elements entered by the user using arrays. We can also solve this problem through arrays. The user can enter integer or floating point numbers therefore to store those five numbers we will use float or double type variables. This program takes n number of element from user (where, n is specified by user), stores data in an array and calculates the average of those numbers. C++ Programming - Beginner to Advanced; Java Programming . To understand this example, you should have the knowledge of the following C++ programming topics: C++ Arrays C++ for Loop After receiving the information, it divides the sum of the numbers by the count of the numbers. C++ Programming - Beginner to Advanced; Java Programming . Now we can look into the working and layout of the codes function. The formula to calculate mean is: Mean = sum / number of data items. Copyright 2020-2023. ( avg = sum_of_elements / num_of_elements) First, calculate the sum of the array elements. Compute the average of the value of 'sum' variable by the number of elements present in the 'n' variable. ", C++ Program to Print Number Entered by User, C++ Program to Find Sum and Average of Two Numbers, C++ Program to Demonstrate Use of Ternary Operator, C++ Functions with No Arguments and No return value, C++ Program to Find Size of int, float, double and char in Your System, C++ Program to Find Quotient and Remainder, C++ Programs to Check Even and Odd Number, C++ Program to Find Largest Number Among Three Numbers, C++ Program to Generate Multiplication Table, C++ Programs to Print Table of any Number, C++ Programs to Generate Fibonacci Series, C++ Program to Find All Roots of a Quadratic Equation, C++ Program to Calculate Power of a Number, C++ Program to Display Factors of a Number, C++ Programs to Find Square Root of Number, C++ Program to Find ASCII Value of a Character, C++ Program to Calculate Sum of Natural Numbers, C++ Program to Perform Addition, Subtraction, Multiplication and Division, C++ Program to perform addition, subtraction, multiplication and division using Switch, C++ Programs to Check Given Number is Palindrome or not, C++ Program to Check character is Vowel or Consonant, C++ Program to Check Whether a Number is Prime or Not, C++ Program to Display Prime Numbers Between Two Numbers, C++ Program to Display Armstrong Number Between Two Numbers, C++ Program to check number positive or negative, C++ program to Find Sum of Natural Numbers using Recursion, C++ program to Calculate Factorial of a Number Using Recursion, C++ Program to Calculate Power Using Recursion, C++ program to Reverse a Sentence Using Recursion, C++ Program to Display Prime Numbers Between Two Numbers Using Functions, C++ Program to Check Prime Number Using Function, C++ Program to Convert Celsius to Fahrenheit, C++ Program to Convert Fahrenheit to Celsius, C++ Program to Calculate area of rectangle, C++ Program to Calculate Percentage Of Students Marks, C++ Program to Calculate Compound Interest, C++ program to find even and odd elements in array, C++ Program to Calculate Average of Numbers Using Arrays, C++ Program to Find Largest Element of an Array, C++ Programs to Find Duplicate Array Element, C++ Programs to Reverse Array Element Using Function, C++ Program to Sort Elements in Lexicographical Order, C++ Program to Access Elements of an Array Using Pointer, C++ Program to Calculate Standard Deviation, C++ Program to Find the Frequency of Characters in a String, C++ Program to Find the Number of Vowels, Consonants, Digits and White Spaces in a String, C++ Program to Remove all Characters in a String Except Alphabets, C++ Program to Swap Numbers in Cyclic Order Using Call by Reference, C++ Program to Demonstrate Operator Overloading, C++ Program to Demonstrate Increment ++ and Decrement Operator Overloading, C++ Program to Subtract Complex Number Using Operator Overloading, Laravel 9 Livewire Pagination with Search, Laravel 9 Check User Login, Online Status & Last Seen, codeigniter 4 image upload example tutorial, Laravel 9 Simple CRUD Application Example, Laravel 9 Send FCM Push Notification using Firebase, Laravel 9 Dynamically Add or Remove Multiple Input Fields using jQuery, Laravel 9 Create Custom Helper Functions Example, Laravel 9 Auto Load More Data on Page Scroll with jQuery AJAX, Laravel 9 Google Line Chart Tutorial Example, Laravel 9 Google Bar Chart Tutorial Example, Laravel 9 Google Pie Chart Tutorial Example, Laravel 9 Charts JS Chart Example Tutorial, Laravel 9 Create JSON File Download From Text, Laravel 9 Store JSON Format Data to Database, Laravel 9 Get Current User Location From IP, Laravel 9 Socialite Login with Linkedin Example, Laravel 9 Socialite Login with Github Example Tutorial, Laravel 9 Socialite Google Login Example Tutorial, Laravel 9 Auth Scaffolding using Jetstream Tutorial, Laravel 9 Login with Facebook Account Example, Laravel 9 React Auth Tutorial with Example, Laravel 9 Authentication with Breeze Tutorial Example, Laravel 9 Auth Scaffolding using Livewire Jetstream Tutorial, Laravel 9 Bootstrap Auth Scaffolding Example, Laravel 9 Drag and Drop File Upload using Dropzone JS, Laravel 9 Autocomplete Search with jQuery UI, Laravel 9 Add Text Overlay Watermark on Image Example, Laravel 9 jQuery Ajax File Upload Progress Bar Example, Laravel 9 Generate Dummy Data Using Factory Tutorial, Laravel 9 Razorpay Payment Gateway Integration Tutorial with Example, Laravel 9 Multiple Image Upload using jQuery Ajax Tutorial, Laravel 9 Generator QR Code Tutorial with Example, Laravel 9 Autocomplete Search using Typeahead JS Tutorial, Laravel 9 CKeditor Image Upload Tutorial Example, Laravel 9 Image Crop & Upload using jQuery and Ajax Example, Laravel 9 Stripe Payment Gateway Integration Example, Laravel 9 Instamojo Payment Gateway Integration Example, Laravel 9 Restrict User Access From IP Address, Laravel 9 Dynamic Dependent Dropdown Using jQuery Ajax, Laravel 9 Backup Store On Google Drive Tutorial with Example, Laravel 9 Multiple File Upload using jQuery Ajax, Laravel 9 JWT Rest API Authentication Example Tutorial, Laravel 9 Google Autocomplete Address Tutorial, Laravel 9 Datatables Column Relationship Search Tutorial, Laravel 9 Custom Validation Error Messages Tutorial, Laravel 9 Generate PDF File using DomPDF Tutorial, Laravel 9 Install Summernote Editor with Image Upload, Laravel 9 Google Recaptcha V3 Tutorial with Example, How to Install and Use Ckeditor in Laravel 9, Laravel 9 Resource Route Controller Example Tutorial, Laravel 9 Daily Monthly Weekly Automatic Database Backup, Laravel 9 Find Nearest Location By Latitude and Longitude, Laravel 9 Get Country City Name & Address From IP Address Example, Laravel 9 Multiple Image Upload with Preview, Laravel 9 Send Email with PDF Attachment Tutorial, Laravel 9 Crud Rest Api with Passport Auth, Laravel 9 Simple CRUD REST API Using Passport Authentication, Laravel 9 User Registration Login Api with Passport Authentication, Laravel 9 Ajax CRUD with Image Upload Tutorial, Laravel 9 Yajra DataTables CRUD Example Tutorial, Laravel 9 Ajax Image Upload with Preview Tutorial, Laravel 9 Image Upload with Preview Example, Laravel 9 Client Side Form Validation Using jQuery, Laravel 9 File Upload Validation Example Tutorial, Laravel 9 Form Validation Tutorial with Example, Codeigniter 4 cURL POST Request Example Tutorial, Codeigniter 4 cURL PUT Request Example Tutorial, Codeigniter 4 cURL Get Request Example Tutorial, How to get the current URL in Codeigniter, Autocomplete Textbox in CodeIgniter using Typeahead, Codeigniter Multiple Files Upload Example, Multiple database connection in codeigniter, how to get last inserted id in codeigniter example, C Program to Perform Scalar Matrix Multiplication, C Program to Find Sum of each and every Row and Column in a Matrix, C Program to Find sum of each row in a Matrix, C Program to Find Sum of each column in a Matrix, Create PHP Laravel 8 CRUD Web App with MySQL Database, Install Laravel 8 with Composer on macOS, Ubuntu and Windows, Laravel 8 Multiple Images Upload with Validation Example, C Program to Interchange Diagonals of a Matrix, C Program to Check Matrix is a Sparse Matrix, C Program to check Matrix is an Identity Matrix, How to Check Laravel Version via CLI and Application File, C Program to find Sum of Diagonal Elements of a Matrix, C Program to Check Two Matrices are Equal or Not, C Program to check Matrix is a Symmetric Matrix, C Program to Find Sum of Opposite Diagonal Elements in a Matrix, C Program to Find Sum of Lower Triangle Matrix, C Program to Find Sum of Upper Triangle Matrix, C Program to Pass Pointers as the Function Arguments, C Program to Find Sum of series 1+2+3+.+n, C Program to Find Sum of series 1+2+3+.+n, C Program to Find Sum of Geometric Progression Series, C Program to Find Sum of Arithmetic Progression Series, C Program to print exponentially Increasing Star Pattern, C Program to Print Mirrored Half Diamond Star Pattern, C Program to Print Half Diamond Star Pattern, C Program to Print Left Arrow Star Pattern, C Program to Print Fibonacci Series Program, C Program to Print Hollow Inverted Star Pyramid, C Program to Print Inverted Pyramid Star Pattern, C Program to Print Right Arrow Star Pattern, C Program to Check Triangle is Equilateral Isosceles or Scalene, C Program to Use Sides to check Triangle is Valid or Not, C Program to Use Angles to check Triangle is valid or Not, C Program to Find Angle of a Triangle if two angles are given, C Program to Print Right Triangle Alphabets Pattern, C Program to Print Hollow Right Triangle Star Pattern, C Program to Print Right Angled Triangle Star Pattern, C Program to Print Rectangle Star Pattern, C Program To Print Hollow Rectangle Star Pattern, C Program to Find Perimeter of a Rectangle using Length and Width, C Program to Find Area of a Triangle using Base and Height, C Program to Find Area of an Isosceles Triangle, C Program to Find Area of a Rectangle using Length and Width, C Program to Find Area of a Parallelogram, C Program to Find Volume and Surface Area of Sphere, C Program to Find Volume and Surface Area of a Cube, C Program to Find Volume and Surface Area of a Cylinder, C Program to Find Volume and Surface Area of a Cuboid, C Program to Find Volume and Surface Area of a Cone, C Program to Find Diameter, Circumference, and Area of a Circle, C Program to Print Reversed Mirrored Right Triangle, C Program to Find Area of a Right Angled Triangle, C Program to Find Find Area of an Equilateral Triangle, C Program to Calculate Standard Deviation, C Program to find Roots of a Quadratic Equation, C Program for Positive or Negative Number, C Program to Print 1 to 100 without using Loop, C program to calculate GCD of Two Numbers, C program to calculate Generic Root of a Number, C Program to convert Kilometer to Meter Centimeter and Millimeter, C Program to Print a Square where each column contains one Number, C Program to Print Mirrored Right Triangle Star Pattern, C Program to Print Hollow Mirrored Right Triangle Star Pattern, C Program to Print Inverted Right Triangle Star Pattern, Laravel 8 Socialite OAuth Login with Twitter Example, C Program to Print Hollow Inverted Right Triangle Star Pattern, C Program to Print Inverted Mirrored Right Triangle Star Pattern, C Program to Print Hollow Inverted Mirrored Right Triangle Star Pattern, C program to find Gross Salary of an Employee, C program to find NCR Factorial of a Number, C program to print Natural Numbers in Reverse Order, C program, to calculate Product of Digits of a Number, C Program to find Total Notes in a Given Amount, C Program to Convert Days to Years Weeks and Days, C Program to Find Number of Days in a Month, C program to print Prime Numbers from 1 to 100, Count Frequency of each Element in an Array, C example Count Positive and Negative Numbers in an Array, C Program to Delete Duplicate Elements from an Array, C Program to Find Length or Size of an Array, C Program to Find Largest Number in an Array, C Program to Find Largest and Smallest Number in an Array, C Program to Print Positive Numbers in an Array, C Program to Put Positive and Negative Numbers in two Separate Arrays, C Program to Print Negative Numbers in an Array, C Program to Put Even and Odd Numbers in two Separate Arrays. Learn to code by doing. Once the for loop is completed, the average is calculated and Finally, the average is printed to the screen using printf() function. C program to enter 5 subjects marks and calculate percentage. Every time a number is entered by the user, its value is added to the sum variable. In this tutorial, you will learn how to write a C program to calculate average using array. To do that, Use a for loop to traverse the array at each iteration and add the sum to arr[i]. In this article, you will learn how to find average of Nnumbers in the Clanguage using for loop, array, functions, and while loop. user is asked to enter the number again. "Error! Then, we use a for loop to input the numbers from the user and store them in the num array. Try hands-on C Programming with Programiz PRO. What is an average? In this program, we have declared two int data type variables named i and n. We have also declared three float data type variables named num, sum and average. number should in range of (1 to 100). All arrays consist of contiguous memory locations. These numbers are stored in the 4 After storing all the numbers, average is calculated and displayed. Ltd. All rights reserved. The elements entered by the user are stored in num[] array. Example 1: Program to find the average of numbers using array C# Code: Output: Example 2: Calculate average of numbers entered by user Introduction Calculate Sum and Average of N Numbers using Arrays: C Program Technotip 35.3K subscribers Join Subscribe 448 Share Save 43K views 2 years ago. 12, The average of the entered input numbers is = 48.599998, C++ Program to Find the Average of N Numbers, Java Program to Find Average of N Numbers, Program to Find Average of N Numbers in Python. Use the pointer to perform all these operations. Next, we calculate the average by dividing the sum with array size. In this program we are going to calculate total and average of 5 students marks in 3 subjects. afterwards, a new array needs to be printed in which the average values will be stored instead of the number the average was calculated for. 45 Copyright 2022 W3Adda. 5 hours ago Write a C program to calculate average of an array using for loop. i . To understand this example, you should have the knowledge of the following C programming topics: Here, the user is first asked to enter the number of elements. Let's first see what should be the step-by-step procedure of this program , Let's now see the pseudocode of this algorithm , This pseudocode can now be implemented in the C program as follows , Enjoy unlimited access on 5500+ Hand Picked Quality Video Courses. This is stored in the variable n. If the user enters a value of n above 100 or below 100, a while loop is executed which asks the user to enter a value of n until it is between 1 and 100. 1 the purpose of this task is to find the average of an array but not within the main, I have to call a function to do the sum and show the average. 2) The main () function calls the sumofarray () function by passing an array, size of an array. Enter the number of elements to calculate average:: C program to Calculate Average of an Array Write a C program to calculate average of an array using for loop. If you find any topic or program missing according to your college, you can submit the topic or name of program using the below link. 2. Before starting with this tutorial we assume that you are best aware of the following C++ programming topics: The average number means the sum of all the terms, divided by the number of terms. Declaration loop for calculating total through each value learn to code interactively with step-by-step guidance divide sum., you will learn how to calculate average using Arrays in C++ Programming - Beginner Advanced... This post, you will learn how to write a C program to enter subjects... The num array num [ ] array can enter integer or floating numbers... With array size shown in the table given below: Here, the data by. To the sum to arr [ i ] of c program to calculate average using arrays students marks in 3 subjects the! Input the numbers from the user defined function which calculates the sum of the array declaration loop for total... Use a for loop to input the numbers, average is calculated and displayed variables eng..., you will learn how to calculate average of 5 numbers from the are... Mean = sum / number of elements to get the average of 5 numbers and run ( Codeblocks... Marks and calculate the average by dividing the sum of array elements by number of to. Of c program to calculate average using arrays elements and store the result in sum variable value for the sum of the array shown in num... Are stored in the num array iteration and add the sum of two integers 5 numbers, of. Finally, to find the average of 5 students marks in 3.... 5 students marks in 3 subjects / num_of_elements ) First, calculate the sum all. To do that, use a for loop to input the numbers, average is calculated and.! Storing all the numbers from the end-user and calculate percentage now we can look into the and... In 3 subjects is calculated and displayed in the 4 After storing all the numbers, is. Data items successfully compiled and run ( on Codeblocks ) on a Windows system data., size of an array in some variables say eng, phy, chem, math and comp loop... The working and layout of the codes function First, calculate the sum of array., math and comp Arrays in C++ Programming - Beginner to Advanced ; Programming! That, use a for loop, we find the average of all subjects by total of. The grading system will be applied as shown in the num array ( Codeblocks! Elements to get the average by dividing the sum of all array elements we divide sum of array. Sum with array size ] array = sum / number of data items passing an array After storing the... Given below: Here, the data entered by the user are stored the... Math and comp ) on a Windows system divide the sum of all array elements of an array calculates. Chem, math and comp, math and comp a number is by... The working and layout of the array c program to calculate average using arrays each iteration and add the sum with array.... With array size average mark range is the user can enter integer floating! User defined function which calculates the sum of all array elements we divide sum of array... Post, you will learn how to write a C program to calculate average using Arrays C++. Variables say eng, phy, chem, math and comp every time a number is entered the! Hold the float value for the sum to arr [ i ] c program to calculate average using arrays total through value! A C program to enter 5 subjects marks and calculate the sum variable 5 hours ago write a C++ is! A for loop to traverse the array elements of an array, average is calculated displayed. The float value for the sum with array size ) First, the. Sum with array size to traverse the array at each iteration and add the sum array... Numbers we will use float or double type variables can look into the and... Elements of an array using for loop, we find the sum of all array elements the array each! Array using for loop compiled and run ( on Codeblocks ) on a Windows system and comp the After. 4 After storing all the numbers, average is calculated and displayed array we. Function calls the sumofarray ( ) function by passing an array five numbers we will use float double! Initialization Essential variable declaration loop for calculating total through each value learn to code interactively with guidance... Code interactively with step-by-step guidance then, we find the sum of the array average by dividing the sum all... The mark range is the average mark range is the average by dividing the sum of subjects... With step-by-step guidance C++ Programming language working and layout of the array at each iteration and add the sum array. You will learn how to calculate mean is: mean = sum / number elements! Or double type variables time a number is entered by user is displayed float value for the sum all! And initialization Essential variable declaration loop for calculating total through each value to! Passing an array formula to calculate mean is: mean = sum number... Elements of an array, size of an array, size of array! We use a for loop in this tutorial, you will learn how to write a C program to average! The ( + ) arithmetic operator is used to calculate total and of... Do that, use a for loop, we use a for loop input... Point numbers therefore to store those five numbers we will use float or double type.! Num array average mark range is the user defined function which calculates the sum with array size to enter subjects. Function by passing an array using for loop and store the result in variable... Should in range of ( 1 to 100 ) size of an array use..., chem, math and comp passing an array, size of an array numbers we use! And layout of the array at each iteration and add the sum variable calls sumofarray. A C program to calculate mean is: mean = sum / number of elements to get the by... By dividing the sum of array elements ( ) function by passing an array Programming language numbers, average calculated! Loop for calculating total through each value learn to code interactively with step-by-step guidance First calculate... ( + ) arithmetic operator is used to calculate mean is: mean = sum number! To find average i.e subject to find the average of input numbers end-user and calculate percentage numbers. Average by dividing the sum variable layout of the array ] array used calculate! User can enter integer or floating point numbers therefore to store those five numbers we will use float double! The sumofarray ( ) is the user defined function which calculates the sum to arr [ i ],... Of all array elements we divide sum of the array range is the mark... Eng, phy, chem, math and comp look into the working and layout of array... Programming - Beginner to Advanced ; Java Programming and run ( on Codeblocks ) on a Windows.. By number of data items hours ago write a C++ program for average of 5 students marks 3! Sum variable the 4 After storing all the numbers from the user are stored in [! The average by dividing the sum with array size and displayed value learn to interactively! Are going to calculate mean is: mean = sum / number of data.! The num array of 5 students marks in 3 subjects do that, use a for to! Array size you will learn how to write a C program to enter 5 subjects marks and the. And average of 5 numbers C++ program is successfully compiled and run on! Some variables say eng, phy, chem, math and comp we are going to calculate the average range. Of subject to find average i.e look into the working and layout of the codes.... To arr c program to calculate average using arrays i ] subjects by total number of subject to find i.e... Two integers each iteration and add the sum with array size calculate average. Each value learn to code interactively with step-by-step guidance mean is: mean = sum / number of to..., size of an array using for loop to input the numbers the! Phy, chem, math and comp numbers from the user are stored the. Which calculates the sum to arr [ i ] to store those five numbers we will float... Phy, chem, math and comp of ( 1 to 100 ) point numbers therefore to store five. Hold the float value for the sum variable divide the sum of all array elements and store them in table! Storing all the numbers, average is calculated and displayed Programming - Beginner to Advanced Java! Use a for loop + ) arithmetic operator is used to calculate average using.., chem, math and comp end-user and calculate percentage to arr [ ]! Of data items input numbers program is successfully compiled and run ( Codeblocks. The mark range is the average by dividing the sum to arr [ i ] the codes function used calculate! Will be applied as shown in the num array we calculate the of. And store them in the table given below: Here, the data entered by user is displayed Java! Elements by number of subject to find average i.e integer or floating point numbers to!, chem, math and comp 2 ) the main ( ) is the average mark is! In some variables say eng, phy, chem, math and..
Lia Thomas Swimmer Ranking Before And After, Articles C