Pages

Showing posts with label Denz Array examples code. Show all posts
Showing posts with label Denz Array examples code. Show all posts

Make a program in which Using binary Search on Denz Array

CODE:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication20
{     
    class Program
    {
        static void Main(string[] args)
        {
            for( int i=0 ; i<1000; i++)
            {
                int  L = -1, R = 10, M;
            double[] MA = { 2.5, 3, 5.5, 7.5, 9.5, 11.5, 13.5, 15.5, 16, 17 };
            double N;
           
                Console.WriteLine("ENTER THE NUMBER:");
                N = Convert.ToDouble(Console.ReadLine());
                while (L + 1 != R)
                {
                    M = (L + R) / 2;
                    if (MA[M] <= N)
                    {
                        L = M;
                    }
                    else
                    {
                        R = M;
                    }
                }
                if ((L >= 0) && (MA[L] == N))
                {
                    Console.WriteLine(" {0} EXIST AT {1} INDEX NUMBER.", N, L + 1);
                }
                else
                {
                    Console.WriteLine(" {0} DOES NOT EXIST.", 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:


Write A PROGAMME ON DENZ ARRAY FOR PRiNTiNG DAYS:

INPUT:

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

namespace Denz_Array
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] array = { "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday" };
            foreach (string day in array)
            {
                Console.WriteLine("{0}", day);
            }
        }
    }
}


OUTPUT: