C#
 Computer >> コンピューター >  >> プログラミング >> C#

最大3つの数値を見つけるC#プログラム


まず、3つの数字を設定しましょう-

int num1, num2, num3;
// set the value of the three numbers
num1 = 10;
num2 = 20;
num3 = 50;

次に、最初の番号と2番目の番号を確認します。 num1> num2の場合、num1とnum3を確認します。 num1がnum3より大きい場合、最大数はnum1であることを意味します。

次のコードを実行して、最大3つの数字を見つけることができます。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Demo {
   class MyApplication {
      static void Main(string[] args) {
         int num1, num2, num3;
         // set the value of the three numbers
         num1 = 10;
         num2 = 20;
         num3 = 50;
         if (num1 > num2) {
            if (num1 > num3) {
               Console.Write("Number one is the largest!\n");
            } else {
               Console.Write("Number three is the largest!\n");
         }
      }
      else if (num2 > num3)
         Console.Write("Number two is the largest!\n");
      else
         Console.Write("Number three is the largest!\n");
      }
   }
}
出力
Number three is the largest!

  1. Pythonで数値を削除して最大の加法スコアを見つけるプログラム

    numsという番号のリストがあるとします。数値を選択し、それを削除して、その数値とそれに隣接する2つの数値の合計でスコアを増やすことができる操作を考えてみましょう。リストの最初または最後の番号を選択しない限り、この操作を何度でも実行できる場合。可能な最大スコアを見つける必要があります。 したがって、入力がnums =[2、3、4、5、6]の場合、出力は39になり、5を選択できるため、合計は(4 + 5 + 6)=15になり、配列は[2、3、4、6]になり、次に4を選択すると、合計は(3 + 4 + 6)=13になり、配列は[2、3、6]になり、3を選択すると、合計は(2 + 3)になります。

  2. 最大3つの数字を見つけるPythonプログラム

    このチュートリアルでは、3つの数字から最大量を見つけるプログラムを作成します。 3つの数字があり、その3つの数字から最大数を見つけることが目標です。 理解を深めるために、いくつかのサンプルテストケースを見てみましょう。 Input: a, b, c = 2, 34, 4 Output: 34 Input: a, b, c = 25, 3, 12 Output: 25 Input: a, b, c = 5, 5, 5 Output: 5 以下の手順に従って、3つの数字の中から最大数を見つけてください。 アルゴリズム 1. Initialise three numbers a, b