Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication60
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] animals = new string[] { "cat", "dog", "mouse", "horse", "donkey", "rabbit", "monkey", "pigeon", "pig", "cow", "hen", "sheep", "shark", "fish", "lion", "tiger", "whale", "sloth", "goat", "chetah" };
- Console.WriteLine("Please enter the animal you would to search for");
- string animal = Console.ReadLine();
- Console.WriteLine("Your location is " + Linearsearch(animal, animals));
- }
- static int Linearsearch(string value, string[] animals)
- {
- for ( int x = 0; x<animals.Length-1; x++)
- {
- if (animals [x] == value)
- {
- return x;
- }
- }
- return -1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement