Write a C# Sharp program to find the missing number in a given array of numbers between 10 and 20

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

Write a C# Sharp program to find the missing number in a given array of numbers between 10 and 20. 
Test Data :
Original array elements:
10
11
12
13
14
15
16
17
18
19
20
Missing number in the said array (10-20): 0
Original array elements:
11
12
13
14
15
16
17
18
19
20
Missing number in the said array (10-20): 10
Original array elements:
10
11
12
13
14
16
17
18
19
20
Missing number in the said array (10-20): 15
Original array elements:
10
11
12
13
14
15
16
17
18
19
Missing number in the said array (10-20): 20

الأجوبة

using System;
using System.Linq;
namespace exercises
{
    class Program
    {
        static void Main(string[] args)
          {
            int[] nums = { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
            Console.WriteLine("Original array elements:");
            Array.ForEach(nums, Console.WriteLine);
            Console.WriteLine("Missing number in the said array (10-20): "+ test(nums));
            int[] nums1 = {11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
            Console.WriteLine("\nOriginal array elements:");
            Array.ForEach(nums1, Console.WriteLine);
            Console.WriteLine("Missing number in the said array (10-20): " + test(nums1));
            int[] nums2 = { 10, 11, 12, 13, 14, 16, 17, 18, 19, 20 };
            Console.WriteLine("\nOriginal array elements:");
            Array.ForEach(nums2, Console.WriteLine);
            Console.WriteLine("Missing number in the said array (10-20): " + test(nums2));
            int[] nums3 = { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };
            Console.WriteLine("\nOriginal array elements:");
            Array.ForEach(nums3, Console.WriteLine);
            Console.WriteLine("Missing number in the said array (10-20): " + test(nums3));
        }
        public static int test(int[] arr)
        {
            return 165 - arr.Sum();
        }
    }
}
هل كان المحتوى مفيد؟

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

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