Queries for counts of array elements with values in given range | Simple C # program to count number of elements with values in given range . ; function to count elements within given range ; initialize result ; check if element is in range ; Driver Code ; Answer queries
using System ; class GFG { static int countInRange ( int [ ] arr , int n , int x , int y ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] >= x && arr [ i ] <= y ) count ++ ; } return count ; } public static void Main ( ) { int [ ] arr = { 1 , 3 , 4 , 9 , 10 , 3 } ; int n = arr . Length ; int i = 1 , j = 4 ; Console . WriteLine ( countInRange ( arr , n , i , j ) ) ; i = 9 ; j = 12 ; Console . WriteLine ( countInRange ( arr , n , i , j ) ) ; } }