Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Write a program that finds the greatest of given 5 variables.
- */
- using System;
- class GreatestVariable
- {
- static void Main()
- {
- decimal[] variable = new decimal[5];
- decimal greatestVariable = 0;
- int i;
- string invalidInput = "Please enter a value between " + decimal.MinValue + " and " + decimal.MaxValue + Environment.NewLine;
- for (i = 0; i < 5; i++)
- {
- Console.WriteLine("Enter value of variable" + (i + 1) + ": ");
- while (!(decimal.TryParse(Console.ReadLine(), out variable[i]) && variable[i] >= decimal.MinValue && variable[i] <= decimal.MaxValue))
- {
- Console.WriteLine(invalidInput);
- Console.WriteLine("Enter value of variable" + (i + 1) + ": ");
- }
- }
- for (int j = 0; j < 5; j++)
- {
- for (int k = 0; k < j; k++)
- {
- if (variable[j] > variable[k])
- {
- greatestVariable = variable[j];
- variable[k] = variable[j];
- }
- else
- {
- greatestVariable = variable[k];
- variable[j] = variable[k];
- }
- }
- }
- Console.WriteLine("The greatest variable is {0}" + Environment.NewLine,greatestVariable);
- Main();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment