작성해야하는 프로그램에 어려움을 겪고 있습니다. 요구 사항은 사용자가 배열 크기로 입력하는 것입니다. 그런 다음 프로그램은 입력 된 값을 표시 한 다음 각 값이 몇 번 발생하는지 배열의 요소를 입력합니다. 모든 것이 제대로 발생하는 부분을 표시하지 않는 한 모든 것이 작동하는 것처럼 보입니다. (배열 크기가 5 임) 또한 이것이하지 못하기 때문에 발생하였습니다 1 2 배, 4는 1 회이다배열 시간 계산 값이
1 occurs 1 time.
1 occurs 1 time.
2 occurs 1 time.
3 occurs 1 time.
4 occurs 2 times.
를 출력 입력 "1 1 2 3 4"라고하자.
static void Main(string[] args)
{
int[] arr = new int[30];
int size,
count=0,
count1=0,
count2=0;
Console.Write("Enter Size of the Array: ");
size = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the elements of an Array: ");
for (int i=0; i < size; i++)
{
arr[i] = Convert.ToInt32(Console.ReadLine());
}
Console.Write("Values Entered: \n");
for (int i = 0; i < size; i++)
{
Console.WriteLine(arr[i]);
if (arr[i] <= 10)
count++;
else
count1++;
}
for(int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
if (arr[i] == arr[j])
count2++;
else
count2 = 1;
}
Console.WriteLine(arr[i] + " Occurs " + count2 + " Times.");
}
Console.WriteLine("The number of valid entries are: " + count + "\nThe number of invalid entries are: " + count1);
Console.ReadKey();
}
이됩니다 Linq를 사용하도록 허용 했습니까? – hatchet
그냥 생각했는데 크기를 말하면 배열을 초기화하는 것이 더 좋지 않겠습니까? 'int [] arr = new arr [size]' – vipersassassin
Linq를 사용할 수 없다면, 사용할 수있는 다른 제약 조건은 무엇입니까? – hatchet