Pages

Showing posts with label Linear searching example codes. Show all posts
Showing posts with label Linear searching example codes. Show all posts

WRITE A PROGRAMME TO SAVE PLAYERS NAME AND SEARCH THEIR ARAY INDEX NUM: BY LINEAR SEARCHING METHOD

INPUT:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Linear_Searching
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("\t\t\t\tPlayer Find");
            string[] player = new String[5];
            string search;
            for (int X = 0; X < 5; X++)
            {
                Console.WriteLine("Enter The Name Of Player {0}",X+1);
                player[X] = Console.ReadLine();

            }
            Console.WriteLine("Which Position U Want To Search");
            search = Console.ReadLine();
            for (int B = 0; B < 5; B++)
            {
                if (player[B] == search)
                {
                    Console.WriteLine("Player Position {0}", B + 1);
                }
            }
        }
    }
}



OUTPUT:


Write A c# program that input user phone num and user name and find the details of user by input Name (Linear Search)

INPUT:

  
       
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication20
{     
    class Program
    {
        static void Main(string[] args)
        {
            char option;
            string find;
            string[,] phone_book = new string[5, 2];
            for (int i = 0; i <= 4; i++)
            {
                for (int j = 0; j <= 1; j++)
                {
                    if (i == 0 && j == 0)
                    {
                        phone_book[i, j] = "Name";
                    }
                    else if (i == 0)
                    {
                        phone_book[i, j] = "Contact";
                    }
                    else if (j == 0)
                    {
                        Console.WriteLine("plz enter the {0} Contact Name", i);
                        phone_book[i, j] = Console.ReadLine();
                    }
                    else if (j == 1)
                    {
                        Console.WriteLine("plz enter the  Contact Number of {0}", phone_book[i,0]);
                        phone_book[i, j] = Console.ReadLine();
                    }
                }
            }
           
            do
            {
                Console.WriteLine("plz enter the contact number or name to dial");
                find = Console.ReadLine();
                for (int i = 0; i <= 4; i++)
                {
                for (int j = 0; j <= 1; j++)
                {
                        if (find == phone_book[i, j])
                        {
                            Console.WriteLine(" Name {0}  Number {1} ", phone_book[i, 0], phone_book[i, 1]);
                        }
                }
                }
                Console.WriteLine("preess y for search again");
                option = Convert.ToChar(Console.ReadLine());
            }
            while (option != 'n');
                }
            }
        }
    
   


   


OUTPUT:


Write a program in which Print the Coming Position of Cricket Players Input by User by Using Linear Search/Denz array.

CODE: ( by Linear Search)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication25
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] batsmans = new string[]{"M Ali","Haeeb","Tahir","Usama","Butt","Afradi","Inzimam","Shoaib","Asad","Raja","Umer"};
            for (int j = 0; j < 11; j++)
            {
                    Console.Write("{0}\t",batsmans[j]);
            }
            Console.WriteLine("\n\nPlz Enter The Name of Batsman for His Coming Position");
            string name = Console.ReadLine();

            Console.WriteLine("At:\t");
            for (int j = 0; j < 11; j++)
            {
                if (batsmans[j] == name)
                {
                    Console.WriteLine(j+1);
                }

            }

        }
    }
}

OUTPUT: