0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Swift】割り算の商と余りが欲しい!!

Posted at

はじめに

私の今までの知識を使って実装します。

let q = 10 / 3
let r = 10 % 3

print("商: \(q), 余り: \(r)") // 商: 3, 余り: 1

まぁ悪くないですが、もっといい方法がありました。

実装

import Foundation

let (q, r) = 10.quotientAndRemainder(dividingBy: 3)

print("商: \(q), 余り: \(r)") // 商: 3, 余り: 1

おわり

Swift知識が増えました

公式ドキュメント

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?