

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to find the Average Values of all the Array Elements in C#?
To find the average values, firstly set an arrayL
int[] myArr = new int[10] { 45, 23, 55, 15, 8, 4, 2, 5, 9, 14 };
Now find the sum and divide it by the length of the array to get the average.
int len = myArr.Length; int sum = 0; int average = 0; for (int i = 0; i < len; i++) { sum += myArr[i]; average = sum / len; }
Let us see the complete code −
Example
using System; public class Program { public static void Main() { int[] myArr = new int[10] { 45, 23, 55, 15, 8, 4, 2, 5, 9, 14 }; int len = myArr.Length; int sum = 0; int average = 0; for (int i = 0; i < len; i++) { sum += myArr[i]; } average = sum / len; Console.WriteLine("Sum = " + sum); Console.WriteLine("Average Of integer elements = " + average); } }
- Related Questions & Answers
- How to find the average of elements of an integer array in C#?
- Find the average of all elements of array except the largest and smallest - JavaScript
- How to find the sum of all array elements in R?
- C# Program to find the average of a sequence of numeric values
- Return the average of the masked array elements in Numpy
- How to loop through all the elements of an array in C#?
- Find the number of operations required to make all array elements Equal in C++
- How to compute Average for the Set of Values using C#?
- How to find the average of non-zero values in a Python dictionary?
- Return the average of the masked array elements axis 1 in Numpy
- Count occurrences of the average of array elements with a given number in C++
- How to find elements of JavaScript array by multiple values?
- Find the average of column values in MySQL using aggregate function
- Return the average of the masked array elements over axis 0 in Numpy
- Return the average of the masked array elements along specific axis in Numpy
Advertisements