Saturday, November 7, 2015

Get the maximum & minimum value

This program gets the maximum & minimum value.

code:

using System;
public class Sample{
  public static void Main(string[] args){
    Console.Write("Input how many numbers you want to compare: ");
 
    int m = int.Parse(Console.ReadLine());
 
    int m2 = m;
    int[] n = new int[m];  
    for(int i=0; i<m; i++){
    n[i] = int.Parse(Console.ReadLine());
    }

    int max = n[0];
    int min = n[0];
    for(int i=0; i<m; i++){
      if(n[i]>max){
      max = n[i];
      }
      if(n[i]<min){
      min = n[i];
      }
     }
      Console.Write("the biggest number: {0} \nthe smallest number: {1}\n", max, min);  
  }
}