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

  • برمجة سي شارب
  • برمجة

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 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

الأجوبة

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;
        }
    }
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...