Write a C# Sharp program to compute the sum of values in a given array of integers except the number 17. Return 0 if the given array has no integer

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

Write a C# Sharp program to compute the sum of values in a given array of integers except the number 17. Return 0 if the given array has no integer

Sample Output:

Sum of values in the array of integers except the number 17: 
32

الأجوبة

using System;
namespace exercises
{
   class Program
    {       
        static void Main(string[] args)
        {       
         Console.WriteLine("Sum of values in the array of integers except the number 17: ");
         Console.WriteLine(test(new[] { 1, 5, 7, 9, 10, 17 })); 
        }           
       static int test(int[] nums)
          {
             int sum = 0;

            for (int i = 0; i < nums.Length; i++)
            {
                if (nums[i] != 17) sum += nums[i];
         }
            return sum;
           }
   } 
}
هل كان المحتوى مفيد؟

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

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