Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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]);
}
}
}
}
}Advertisements