

- 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 compute Average for the Set of Values using C#?
Firstly, set an array with values −
int[] myArr = new int[] { 34, 23, 77, 67 };
To get the average, firstly get the sum of array elements.
Divide the sum with the length of the array and that will give you the average of the elements −
int sum = 0; int average = 0; for (int i = 0; i < len; i++) { sum += myArr[i]; } average = sum / len;
The following is the complete code to get the array in C# −
Example
using System; public class Program { public static void Main() { int[] myArr = new int[] { 34, 23, 77, 67 }; 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("Average = " + average); } }
Output
Average = 50
- Related Questions & Answers
- Find the average of column values in MySQL using aggregate function
- How to find the Average Values of all the Array Elements in C#?
- How to set only numeric values for edittext in Android using Kotlin?
- How to compute the area of a set of bounding boxes in PyTorch?
- How to get the possible values for SET field in MySQL?
- How to find the average of non-zero values in a Python dictionary?
- C# Program to find the average of a sequence of numeric values
- MySQL query to calculate the average of values in a row?
- How to select documents with values above the average in MongoDB?
- How to display average line for y variable using ggplot2 in R?
- MySQL query to set values for NULL occurrence
- Determine whether there is a pair of values in the array where the average of the pair equals to the target average in JavaScript
- How to Set/modify the pixels(RGB values) of an image using Java OpenCV Library?
- Program to count average of all special values for all permutations of a list of items in Python
- C++ Program to Compute Combinations using Recurrence Relation for nCr
Advertisements