Venciity

[Jumpstart C#] ArraysAndLists TASK16

Feb 24th, 2014
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.91 KB | None | 0 0
  1. /*Задача М1-16.
  2.  * Даден е числов масив. Да се провери дали той е подреден и да се от­печата един от следните резултати:
  3. -Масивът е с равни еле­менти.
  4. -Масивът е със строго нарастващи еле­мен­ти.
  5. -Масивът е с нестрого нарастващи еле­мен­ти.
  6. -Масивът е със строго намаляващи еле­мен­ти.
  7. -Масивът е с нестрого намаляващи еле­мен­ти.
  8. -Масивът не е подреден.     */
  9.  
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15.  
  16. namespace task16
  17. {
  18.     class Program
  19.     {
  20.         static void Main(string[] args)
  21.         {
  22.             Console.Write("Enter array length: ");
  23.             int length = int.Parse(Console.ReadLine());
  24.             int[] myArray = new int[length];
  25.  
  26.             //enter array elements
  27.             for (int index = 0; index < myArray.Length; index++)
  28.             {
  29.                 Console.Write("Number {0} = ", index + 1);
  30.                 myArray[index] = int.Parse(Console.ReadLine());
  31.             }
  32.  
  33.             bool isAllEqual = true;
  34.             bool isIncreasing = true;
  35.             bool isStrictlyIncreasing = true;
  36.             bool isDecreasing = true;
  37.             bool isStrictlyDecreasing = true;
  38.  
  39.             for (int i = 0; i < myArray.Length-1; i++)
  40.             {
  41.                 if (myArray[i] != myArray[i+1])
  42.                 {
  43.                     isAllEqual = false;
  44.                 }
  45.                 if (myArray[i] < myArray[i + 1])
  46.                 {
  47.                     isDecreasing = false;
  48.                 }
  49.                 if (myArray[i] <= myArray[i + 1])
  50.                 {
  51.                     isStrictlyDecreasing = false;
  52.                 }
  53.                 if (myArray[i] > myArray[i + 1])
  54.                 {
  55.                     isIncreasing = false;
  56.                 }
  57.                 if (myArray[i] >= myArray[i + 1])
  58.                 {
  59.                     isStrictlyIncreasing = false;
  60.                 }
  61.             }
  62.  
  63.             if (isAllEqual)
  64.             {
  65.                 Console.WriteLine("All equal");
  66.             }
  67.             else if (isStrictlyIncreasing)
  68.             {
  69.                 Console.WriteLine("Strictly increasing");
  70.             }
  71.             else if (isIncreasing)
  72.             {
  73.                 Console.WriteLine("Increasing");
  74.             }
  75.             else if (isStrictlyDecreasing)
  76.             {
  77.                 Console.WriteLine("Strictly Decreasing");
  78.             }
  79.             else if (isDecreasing)
  80.             {
  81.                 Console.WriteLine("Decreasing");
  82.             }
  83.             else
  84.             {
  85.                 Console.WriteLine("Unsorted");
  86.             }
  87.         }
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment