A simple program to ask the user to give a series of numbers and then the program will compute the difference between the largest and smallest number in C# programming language.
My email address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com
Program Listing
// High_Low.cs
// Prof. Jake Rodriguez Pomperada,MAED-IT, MIT
// www.jakerpomperada.blogspot.com / www.jakerpomperada.com
// jakerpomperada@gmail.com
// Bacolod City, Negros Occidental Philippines
using System;
namespace exercises
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("\n");
Console.WriteLine("\tDifference between the largest and smallest value in C# ");
int[] arr = new int[10];
int small_num = 0, biggest_num = 0;
int i;
Console.WriteLine("\n");
Console.Write("\tInput 10 elements in the array :\n");
Console.WriteLine("\n");
for (i = 0; i < 10; i++)
{
Console.Write("\tGive value in Item No. {0} : ", (i+1));
arr[i] = Convert.ToInt32(Console.ReadLine());
}
if (arr.Length > 0) small_num = biggest_num = arr[0];
for ( i = 1; i < arr.Length; i++)
{
small_num = Math.Min(small_num, arr[i]);
biggest_num = Math.Max(biggest_num, arr[i]);
}
Console.WriteLine("\n");
Console.Write("\tThe difference is {0}. ", biggest_num- small_num);
}
}
}
No comments:
Post a Comment