wingman007

EnterArrayPrintOddElements

Sep 21st, 2016
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Excercise2
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n;
  14.             Console.Write("Please, enter the size of the array: ");
  15.             string input = Console.ReadLine();
  16.             n = int.Parse(input);
  17.  
  18.             int[] myArray;
  19.             myArray = new int[n];
  20.  
  21.             EnterElements(myArray);
  22.             PrintOddBiggerThat5(myArray);
  23.         }
  24.  
  25.         static void EnterElements(int[] a)
  26.         {
  27.             for (int i = 0; i < a.Length; i++)
  28.             {
  29.                 Console.Write("Please enter the value of myArray[{0}] = ", i);
  30.                 a[i] = int.Parse(Console.ReadLine());
  31.             }
  32.         }
  33.  
  34.         static void PrintOddBiggerThat5(int[] a)
  35.         {
  36.             for (int i = 0; i < a.Length; i++)
  37.             {
  38.                 if (a[i] % 2 == 1 && a[i] > 5) Console.WriteLine(a[i]);
  39.             }
  40.         }
  41.  
  42.     }
  43. }
Add Comment
Please, Sign In to add comment