Q:

Write a C# Sharp program to check if the value of each element is equal or greater than the value of previous element of a given array of integers

0

Write a C# Sharp program to check if the value of each element is equal or greater than the value of previous element of a given array of integers

Sample Output:

False
True
True
True

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;
namespace exercises
{
   class Program
    {       
        static void Main(string[] args)
        {               
         Console.WriteLine(test(new[] { 5, 5, 1, 5, 5 })); 
         Console.WriteLine(test(new[] { 1, 2, 3, 4 })); 
         Console.WriteLine(test(new[] { 3, 3, 5, 5, 5, 5})); 
         Console.WriteLine(test(new[] { 1, 5, 5, 7, 8, 10})); 
          }               
        static bool test(int[] numbers)
         {
          for (int i = 0; i < numbers.Length - 1; i++)
            {
                if (numbers[i + 1] < numbers[i]) return false;
            }

            return true;
         }
    
    } 
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now