Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Задача М1-16.
- * Даден е числов масив. Да се провери дали той е подреден и да се отпечата един от следните резултати:
- -Масивът е с равни елементи.
- -Масивът е със строго нарастващи елементи.
- -Масивът е с нестрого нарастващи елементи.
- -Масивът е със строго намаляващи елементи.
- -Масивът е с нестрого намаляващи елементи.
- -Масивът не е подреден. */
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace task16
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.Write("Enter array length: ");
- int length = int.Parse(Console.ReadLine());
- int[] myArray = new int[length];
- //enter array elements
- for (int index = 0; index < myArray.Length; index++)
- {
- Console.Write("Number {0} = ", index + 1);
- myArray[index] = int.Parse(Console.ReadLine());
- }
- bool isAllEqual = true;
- bool isIncreasing = true;
- bool isStrictlyIncreasing = true;
- bool isDecreasing = true;
- bool isStrictlyDecreasing = true;
- for (int i = 0; i < myArray.Length-1; i++)
- {
- if (myArray[i] != myArray[i+1])
- {
- isAllEqual = false;
- }
- if (myArray[i] < myArray[i + 1])
- {
- isDecreasing = false;
- }
- if (myArray[i] <= myArray[i + 1])
- {
- isStrictlyDecreasing = false;
- }
- if (myArray[i] > myArray[i + 1])
- {
- isIncreasing = false;
- }
- if (myArray[i] >= myArray[i + 1])
- {
- isStrictlyIncreasing = false;
- }
- }
- if (isAllEqual)
- {
- Console.WriteLine("All equal");
- }
- else if (isStrictlyIncreasing)
- {
- Console.WriteLine("Strictly increasing");
- }
- else if (isIncreasing)
- {
- Console.WriteLine("Increasing");
- }
- else if (isStrictlyDecreasing)
- {
- Console.WriteLine("Strictly Decreasing");
- }
- else if (isDecreasing)
- {
- Console.WriteLine("Decreasing");
- }
- else
- {
- Console.WriteLine("Unsorted");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment