Ad
Algorithms
Logic
Mathematics
Numbers

I want to show you task from Russian EGE exam

Given an array containing positive integers that do not exceed 15000. Find the number of even elements in the array that are not multiples of 3, replace all odd elements that are multiples of 3 with this number, and output the modified array. For example, for a source array of five elements 20, 89, 27, 92, 48, the program must output numbers 20, 89, 2, 92, 48.

using System;
 public class RussianExam
  {
    public static int[] ExamTask(int[] array)
        {
            int count = 0;
            for(int i = 0; i < array.Length; i++)
            {
                if (array[i] % 3 != 0 && array[i] % 2 == 0) count++;
            }
            for (int i = 0; i < array.Length; i++)
            {
                if (array[i] % 3 == 0 && array[i] % 2 != 0) array[i] = count;
            }
            return array;
        }
  }