Created
          May 7, 2023 06:59 
        
      - 
      
 - 
        
Save KaitoMuraoka/4ffeb5738eee56e07e8e6c27de7bd5a2 to your computer and use it in GitHub Desktop.  
    条件式をわかりやすく書く(1)
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // 点(x, y)が第何象限にあるか(1, 2, 3, 4)を返す関数 | |
| // ただし、それでもなければ0を返すようにした | |
| private func quadrant(x: Int, y: Int) -> Int { | |
| if (0 < x && 0 < y) { | |
| return 1 | |
| } else if (0 > x && 0 < y) { | |
| return 2 | |
| } else if (0 > x && 0 > y) { | |
| return 3 | |
| } else if (0 < x && 0 > y) { | |
| return 4 | |
| } else { | |
| return 0 | |
| } | |
| } | |
| func main() { | |
| print(quadrant(x: 1, y: 2)) | |
| print(quadrant(x: -1, y: -3)) | |
| print(quadrant(x: -2, y: 1)) | |
| print(quadrant(x: -3, y: -2)) | |
| print(quadrant(x: 2, y: -1)) | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment