C# program to check if all the values in a list that are greater than a given value


Let’s say you need to find the elements in the following list to be greater than 80.

int[] arr = new int[] {55, 100, 87, 45};

For that, loop until the array length. Here, res = 80 i.e. the given element.

for (int i = 0; i < arr.Length; i++) {
   if(arr[i]<res) {
      Console.WriteLine(arr[i]);
   }
}

The following is the complete code −

Example

using System;
namespace Demo {
   public class Program {
      public static void Main(string[] args) {
         int[] arr = new int[] {
            55,
            100,
            87,
            45
         };
         // given integer
         int res = 80;
         Console.WriteLine("Given Integer {0}: ", res);
         Console.WriteLine("Numbers larger than {0} = ", res);
         for (int i = 0; i < arr.Length; i++) {
            if (arr[i] > res) {
               Console.WriteLine(arr[i]);
            }
         }
      }
   }
}

Updated on: 22-Jun-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements