다음 목록에서 80보다 큰 요소를 찾아야 한다고 가정해 보겠습니다.
int[] arr = new int[] {55, 100, 87, 45}; 이를 위해 배열 길이까지 반복합니다. 여기에서 res =80, 즉 주어진 요소입니다.
for (int i = 0; i < arr.Length; i++) {
if(arr[i]<res) {
Console.WriteLine(arr[i]);
}
} 다음은 완전한 코드입니다 -
예시
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]);
}
}
}
}
}