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: Find the missing number in a given array of numbers between 10 and 20

C# Sharp Array: Exercise-34 with Solution

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

Sample Solution:-

C# Sharp Code:

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();
        }

    }
}

Sample Output:

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
 

Flowchart:

Flowchart: Find the missing number in a given array of numbers between 10 and 20.

C# Sharp Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a C# Sharp program to remove all duplicate elements from a given array and returns a new array.
Next: Write a C# Sharp program to calculate the sum of two lowest negative numbers of a given array of integers.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.