1. 程式人生 > >C#---計算兩個數的最大值

C#---計算兩個數的最大值

                                  計算兩個數的最大值

題目要求:輸入兩個數,並比較兩個數的大小。輸出兩個數的最大值。

程式碼實現:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ConsoleApplication7
{
    class Fa
    {
        public static int Max(int a, int b)
        {
            if (a > b)
                return a;
            else
                return b;
        }
 
    }
    class Program
    {
        static void Main(string[] args)
        {
            int a;
            int b;
            Console.WriteLine("請分別輸入兩個數的值");
            a = Convert.ToInt32(Console.ReadLine());
            b = Convert.ToInt32(Console.ReadLine());
            Console.Write("輸入的兩個數的值分別為a={0}, b={1}", a, b);
            Console.WriteLine("它們的最大值為max={0}",Fa.Max(a, b));
            Console.ReadKey();
 
 
        }
    }
}

相關推薦

C#---計算個數

                                  計算兩個數的最大值題目要求:輸入兩個數,並比較兩個數的大小。輸出兩個數的最大值。程式碼實現:using System; using System.Collections.Generic; using Syst

初學Java:計算陣列中 ---計算陣列中----計算陣列之和----實現個陣列----拼接陣列擷取

public class ArrayUtils{ //建立類(陣列工具類) //1.計算陣列中最大值 public static int arrayMaxElement(int [] data){ //建立方法 if(data == null){

Java:定義五個函式,分別實現①計算陣列的MAX②MIN③陣列和SUM④拼接個陣列a和b⑤擷取a陣列的一部分

import java.io.IOException; public class Arr8{ //1.計算陣列中最大值 public static int arrayMaxElement(int [] data){ if(data == null){

(C語言)用函式實現求三個數

題目描述:從鍵盤輸入三個數,之後呼叫函式實現求三個數的最大值 程式碼實現: #include<stdio.h> int main() { int qmax(int a,int b,int c); //求最大值函式的宣告 int x,y,z; int max

求出C程式

1.不使用判斷語句 #include <stdio.h> #include <math.h> double Max(double a, double b) { double q = sqrt((a-b)*(a-b)); return

課堂練習--計算陣列的,平均值,標準差,中位數;numpy.random模組提供了產生各種分佈隨機數的陣列;正態分佈;Matplotlib

#計算陣列的最大值,最小值,平均值,標準差,中位數 import numpy as np a=np.array([1, 4, 2, 5, 3, 7, 9, 0]) print(a) a1=np.max(a) #最大值 print(a1) a2=np.min(a) #最小值 print(a2) a3

JAVA——計算陣列的,陣列的和,數組合並,陣列擷取

1,計算陣列的最大值 2,計算陣列的最小值 3,計算陣列和 4,合併陣列 5,擷取陣列 public class ArrayEvent{ //1,計算陣列中的最大值 public static int arrMax(int[] arr1){ if(arr1 == null){

C# 獲取表中

int startmaxid = 0; if (db.LPicture.Any()) { // LPicture Newmode = db.LPicture.Where(n => ).FirstOrDe

手動輸入一串陣列int型別的 獲取其中的 用冒泡

int [] ary = new int[10]; Scanner sc = new Scanner(System.in); for (int i = 0; i < ary.length; i++) { System.out.print("請

個數(if)

輸入三個數,輸出最大值; #include<stdio.h> int main() {     int a,b,c,max;     scanf("%d%d%d",&a,&

C/C++學習:求函式

問題 兩週實訓,第四題:求最大值函式。 問題描述:從鍵盤輸入兩個double型別資料,a,b,通過定義並呼叫函式max_ab實現求a與b的最大值輸出。 解題 完整程式碼: /* Module Name:求最大值函式 Module

c++求陣列中

用algorithm中的max_elementmin_element這兩個函式返回的是位置指標,*max_element可以獲得最大值1)普通陣列用法!#include <algorithm>int main(){    int a[5] = { 2, 3, 5,

重拾C語言-函式定義計算個數

程式碼片段 #include <stdio.h> // 函式宣告 int _max( int num1, int num2 ); int main() { /

C++求個數

eof sizeof ios int sig turn c++ a + b -a //不使用if,:?等推斷語句。求兩個數字中最大的那個數字。 #include<iostream> using namespace std; int main(

C語言實現求個數C語言實現雞兔同籠問題

實驗三:輸入兩個數求最大者 #include<stdio.h> int main()//主函式 { int max(int x,int y); int a,b,c; printf("請輸入a:\n"); scanf("%d",&a); pr

[c語言] 呼叫函式實現求個數中的

#include<stdio.h>int max(int x, int y){int max = 0;if (x < y){max = y;}else{max = x;}return

C#練習——用方法實現個數

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T

51nod_1179_計算N個數之間之間GCD的

#include<iostream> #include<cstdio> using namespace std; const int maxs = 1e6 + 10

編寫C#程序,計算去除之後的平均值

pub ole eric efault lis ner .get ast c# 有10位評委對跳水運動員做評分,編寫C#程序,計算去除最大得分和最小得分之後的平均得分 作為運動員的跳水成績。 interface IMark using System.Collections

1.交換內容 2.不創建臨時變量交換只內容 3.求十個數中的 4.講三個數到小輸出 5.求個數大公約數

www. 最大公約數 十個 following .com blank 臨時變量 lan follow 露x都對貝姨芽沽1才39賢http://www.facebolw.com/space/2104128 ZP鋪巢嗣3瀉HX7Dhttp://www.facebolw.com