Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

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:

Flowchart: C# Sharp Exercises - Check the average value of the elements of a given array of numbers is a whole number or not.

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.