Ad
Code
Diff
  • fn odd_count(n: u64) -> u64 {
        n / 2
    }
    • #import <Foundation/Foundation.h>
    • @interface SampleClass:NSObject
    • /* method declaration */
    • - (int)odd_count:(int)n;
    • @end
    • @implementation SampleClass
    • - (int) odd_count:(int) n{
    • //your code here
    • int odd_counter = 0;
    • for (int i = 1; i < n; i=i+2) {
    • // Numbers that are divisible by 2
    • if (i % 2 != 0)
    • odd_counter++;
    • }
    • return odd_counter;
    • }
    • @end
    • fn odd_count(n: u64) -> u64 {
    • n / 2
    • }