Venciity

[Jumpstart C#] homework loops - paris of numbers

Jan 24th, 2014
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.62 KB | None | 0 0
  1. /*Напишете програма която приема вход от клавиатурата цяло число n >= 2
  2.  * и отпечатва на екрана всички възможни двойки числа в интервала [1..n] .
  3.  * Двойките N M и M N се считат за еднакви,
  4.  * затова да се отпечата само една от двете.
  5.  
  6. Например за n = 3 изхода ще е:
  7. 1 2
  8. 1 3
  9. 2 3   */
  10.  
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16.  
  17. namespace _3.EX
  18. {
  19.     class Program
  20.     {
  21.         static void Main(string[] args)
  22.         {
  23.             Console.Write("Enter the numbers count: ");
  24.             int numberCount = int.Parse(Console.ReadLine());
  25.             int[] numberArray = new int[numberCount];
  26.  
  27.             for (int i = 0; i < numberCount; i++)
  28.             {
  29.                 numberArray[i] = int.Parse(Console.ReadLine());
  30.             }
  31.  
  32.  
  33.             // Solution using loop and if statement
  34.             int minimum = numberArray[0];
  35.             int maximum = numberArray[0];
  36.             for (int i = 0; i < numberArray.Length; i++)
  37.             {
  38.                 if (maximum < numberArray[i])
  39.                 {
  40.                     maximum = numberArray[i];
  41.                 }
  42.                 if (minimum > numberArray[i])
  43.                 {
  44.                     minimum = numberArray[i];
  45.                 }
  46.             }
  47.             Console.WriteLine("Mnimum = {0}",minimum);
  48.             Console.WriteLine("Maximum = {0}",maximum);
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment