2
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?

割り算の商と余りを一行で表示する[C#]

Last updated at Posted at 2025-05-18

はじめまして、noirです。Qiita投稿は初めてです。

軽く自己紹介をします。私は現役の大学生で、大学の授業ではPythonとC言語の基礎を履修済みです。最近C#とUnityの勉強を始めました。備忘録のため、Qiitaに投稿をしてみようと思います。周りの方々に比べるとまだまだ拙い箇所がありますが、暖かい目で見守ってください…。

問題文へのリンクはこちらです

解答

using System;

class Program
{
    public static void Main()
    {
        int remainder;
        
        int quotient = Math.DivRem(437326, 9085, out remainder);
        
        Console.WriteLine("{0} {1}",quotient, remainder);
    }
}

解説

商...quotient , 余り...remainderとします。

Math.Divrem は整数の割り算を行い、商と余りの両方を得ることができるメソッドです。

ここで、Console.WriteLine(quotient1, remainder1);と書くと、上手くできません。そこで、Console.WriteLine("{0} {1}", quotient1, remainder1);
{0} が最初の引数(quotient1)、{1} が次の引数(remainder1)に置き換わります。

以上です。ここまで読んでいただきありがとうございました。

2
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
2
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?