C# Sharp Exercises: Check the average value of the elements of a given array of numbers is a whole number or not
C# Sharp Basic: Exercise-72 with Solution
Write a C# Sharp program to check whether the average value of the elements of a given array of numbers is a whole number or not.
Sample Solution:
C# Sharp Code:
using System;
using System.Linq;
namespace exercises
{
class Program
{
static void Main(string[] args)
{
int[] nums = { 1, 2, 3, 5, 4, 2, 3, 4 };
Console.WriteLine("Check the average value of the said array is a whole number or not: " + test(nums));
int[] nums1 = { 2, 4, 2, 6, 4, 8 };
Console.WriteLine("Check the average value of the said array is a whole number or not: " + test(nums1));
}
public static bool test(int[] arr_nums)
{
return arr_nums.Average() % 1 == 0;
}
}
}
Sample Output:
Check the average value of the said array is a whole number or not: True Check the average value of the said array is a whole number or not: False
Flowchart:
C# Sharp Code Editor:
Improve this sample solution and post your code through Disqus
Previous: Write a C# Sharp program to check if a given string contains two similar consecutive letters.
Next: Write a C# Sharp program to convert the letters of a given string (same case-upper/lower) into alphabetical order.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework