Likes

C# LAB at HoM 9

john needs to create a program that defines a charcter array with five elements. he also needs to accept a character the user, and count the number of times charactet in the character array.


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace ConsoleApplication4



{

 class duplicate



{

 static void Main(string[] args)



{

 char[] ch = new char[5] { 'a', 'b', 'a', 'c', 'd' };

 int i, count = 0;

 Console.WriteLine("enter a character:");

 char input = Convert.ToChar(Console.ReadLine());

 for (i = 0; i < 5; i++)
{

 if (ch[i] == input)
{

count++;

}

}

 Console.WriteLine("{0} appears {1} times in the character array", input, count);

 Console.ReadLine();

}

}

}





Sam is working on an application wherein he needs to accept the size of a one dimensional array and its values. He needs to identify the largest and smallest number in the array and based on that he needs to display the result. Help him to create the application.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] io=new int[3]{5,4,6};
            Console.WriteLine("Sam is working on an application wherein he needs to accept the size of a one dimensional array and its values. He needs to identify the largest and smallest number in the array and based on that he needs to display the result. Help him to create the application.  ");
            if(io[0]>io[1] && io[0]>io[2])
            {
                Console.WriteLine("the largest number is:" + io[0]);
            }
            if (io[1] > io[0] && io[1] > io[2])
            {
                Console.WriteLine("the largest number is:" + io[1]);
            }
            if (io[2] > io[0] && io[2] > io[1])
            {
                Console.WriteLine("the largest number is:" + io[2]);
            }
            if (io[0] < io[1] && io[0] < io[2])
            {
                Console.WriteLine("the smallest number is:" + io[0]);
            }
            if (io[1] < io[0] && io[1] < io[2])
            {
                Console.WriteLine("the smallest number is:" + io[1]);
            }
            if (io[2] < io[0] && io[2] < io[1])
            {
                Console.WriteLine("the smallest number is:" + io[2]);
            }
            Console.ReadLine();
        }
    }
}




lab @ home 9 ..... jhon wants to enter player name (range int 1 to 4)


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

namespace ConsoleApplication20
{
    class Program
    {
        static void Main(string[] args)
        {
            int a,i;
            Console.WriteLine("enter the number of players");
            a=Convert.ToInt32(Console.ReadLine());

            string[] arr= new string [a];
            for(i=0;i<a;i++)
            {
                arr[i]=Console.ReadLine();
            }
            for (i = 0; i < a; i++)
            {
                Console.WriteLine("name of player:" + arr[i]);
            }
            Console.ReadLine();
        }
    }
}

No comments: