Skip to content

Instantly share code, notes, and snippets.

@TheMuellenator
Last active October 27, 2024 17:19
Show Gist options
  • Save TheMuellenator/9fe2f689a3e1d9aec2fd631bd98ec606 to your computer and use it in GitHub Desktop.
Save TheMuellenator/9fe2f689a3e1d9aec2fd631bd98ec606 to your computer and use it in GitHub Desktop.
iOS repl.it - Functions 3 Challenge Solution
func isOdd(n: Int) -> Bool {
if n % 2 != 0 {
return true
} else {
return false
}
// Alternatively:
// return n % 2 != 0
}
let testNumber = Int(readLine()!)!
let numberIsOdd = isOdd(n: testNumber)
print(numberIsOdd)
@Magdalenaspace
Copy link

func isOdd(n: Int) -> Bool { return n % 5 != 0 }

let numberIsOdd = isOdd(n: 53)
print(numberIsOdd)

@b-abdenoure
Copy link

i used this
f```
unc isOdd (n: Int) -> Bool{
if n % 2 == 0 {
return false
}else{
return true
}
}

there is many way to make it work

@EdoardoTunzi
Copy link

THIS ONE WORKED FINE FOR ME:

func isOdd(n: Int) -> Bool {
if n % 2 == 1 {
return true
} else {
return false
}
}

@SemennikovNA
Copy link

func isOdd(n: Int) -> Bool {
if n.isMultiple(of: 2) {
return false
} else {
return true
}
}

@ArmandaMendes
Copy link

func isOdd(n: Int) -> Bool {
if n % 2 == 1 {
return true
} else {
return false
}
}

isOdd(n: 5)

@Devavrat01
Copy link

func isodd(n: Int) -> Bool{
if (n % 2 == 0)
{
return true
} else
{
return false
}
}
var doorShouldopen = isodd(n: 5 )
print(doorShouldopen)

@vsiddharth-suki
Copy link

A one-liner:

func isOdd(n: Int) -> Bool {
    return n & 1 == 1
}

@RenuckaM
Copy link

func isOdd(n: Int) -> Bool{
if n % 2 != 0 {
return true
}else{
return false
}
}

@Shah0651
Copy link

func isOdd(n: Int) -> Bool{
    return n % 2 != 0
    
}


//Try some different numbers below:
//The code below is not part of the exercise, but you can test your own code with different numbers.
let numberIsOdd = isOdd(n: 52)
print(numberIsOdd)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment