Weewee21

CheckIfNumberIsInArrayIfTruePrintTrueAndCountTimesAppears

May 5th, 2021
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.30 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp1
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Console.WriteLine("Array Length is size of 1 to 100 Whole Numbers");
  10.  
  11.             Console.WriteLine("Please enter array size from 1 to 100");
  12.             int arraySize = int.Parse(Console.ReadLine());
  13.  
  14.             int[] numberSet = new int[arraySize];
  15.  
  16.             bool contains = false;
  17.  
  18.             int count = 0;
  19.  
  20.             Console.WriteLine("Please enter a number between 1 to 100 and we'll tell you if it's inside the array");
  21.             int theNumber = int.Parse(Console.ReadLine());
  22.  
  23.             for (int i = 0; i < arraySize; i++)
  24.             {
  25.                 Console.WriteLine("Enter number: {0}", i + 1);
  26.                 int someNumber = int.Parse(Console.ReadLine());
  27.  
  28.                 numberSet[i] = someNumber;
  29.  
  30.                 contains = Work(numberSet[i]);
  31.  
  32.                 if (numberSet[i] == theNumber)
  33.                 {
  34.                     count++;
  35.                     contains = true;
  36.                 }
  37.             }
  38.  
  39.             if (numberSet.Length == arraySize)
  40.             {
  41.                 Console.WriteLine("");
  42.                 Console.WriteLine(contains);
  43.                 Console.WriteLine(count);
  44.             }
  45.         }
  46.     }
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment