Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Problem1
- {
- class Program
- {
- static void Main(string[] args)
- {
- //Да се напише програма, която създава масив с 20 елемента от целочислен тип и инициализира всеки от елементите със стойност равна на индекса на елемента умножен по 5.
- //Елементите на масива да се изведат на конзолата.
- //Използвайте масив int[] и for цикъл.
- int[] array = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
- Console.Write("Output: ");
- for (int index = 0; index < array.Length; index++)
- {
- //Multiply the number by 5
- array[index] = 5 * array[index];
- //Print the number
- Console.Write(array[index] + " ");
- }
- }
- }
- }
- using System;
- namespace Problem2
- {
- class Program
- {
- static void Main(string[] args)
- {
- // Да се напише програма, която чете два масива от конзолата и проверява дали са еднакви.
- // Два масива са еднакви, когато имат еднаква дължина и стойностите на елементите в тях съответно съвпадат.Второто условие можете да проверите с for цикъл.
- Console.WriteLine("Please enter the length of the FIRST Array:");
- int f = int.Parse(Console.ReadLine());
- int[] firstArr = new int[f];
- Console.WriteLine("Please enter the length of the SECOND Array:");
- int s = int.Parse(Console.ReadLine());
- int[] secondArr = new int[s];
- if (firstArr.Length != secondArr.Length)
- {
- Console.WriteLine("Error! The FIRST Array length and the SECOND Array length are not equal. Please try again and enter EQUAL array lengths");
- }
- for (int i = 0; i <= firstArr.Length - 1; i++)
- {
- Console.WriteLine("Please enter the {0} number of FIRST array", i);
- firstArr[i] = int.Parse(Console.ReadLine());
- }
- for (int i = 0; i <= secondArr.Length - 1; i++)
- {
- Console.WriteLine("Please enter the {0} number of SECOND array", i);
- secondArr[i] = int.Parse(Console.ReadLine());
- }
- bool areEqual = true;
- for (int i = 0; i < secondArr.Length; i++)
- {
- if (firstArr[i] != secondArr[i])
- {
- areEqual = false;
- break;
- }
- }
- Console.WriteLine("The two arrays are equal: {0}", areEqual);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement