Semaphores solution.
Approach\nSemaphores solution.\n\n# Code\n\nusing System.Threading;\n\npublic class ZeroEvenOdd {\n    private int n;\n    private static Semaphore zero_semapho
# Approach\nSemaphores solution.\n\n# Code\n```\nusing System.Threading;\n\npublic class ZeroEvenOdd {\n    private int n;\n    private static Semaphore zero_semaphore = new (1, 1);\n    private static Semaphore even_semaphore = new (0, 1);\n    private static Semaphore odd_semaphore = new (0, 1);\n\n    public ZeroEvenOdd(int n)\n    {\n        this.n = n;\n    }\n\n    // printNumber(x) outputs "x", where x is an integer.\n    public void Zero(Action<int> printNumber)\n    {\n        for (int i = 1; i <= n; i++)\n        {\n            zero_semaphore.WaitOne();\n            printNumber(0);\n            if (i % 2 == 0)\n            {\n                even_semaphore.Release();\n            }\n            else\n            {\n                odd_semaphore.Release();\n            }\n        }\n    }\n\n    public void Odd(Action<int> printNumber)\n    {\n        for (int i = 1; i <= n; i += 2)\n        {\n            odd_semaphore.WaitOne();\n            printNumber(i);\n            zero_semaphore.Release();\n        }\n    }\n\n    public void Even(Action<int> printNumber)\n    {\n        for (int i = 2; i <= n; i += 2)\n        {\n            even_semaphore.WaitOne();\n            printNumber(i);\n            zero_semaphore.Release();\n        }\n    }\n}\n```
['C#']