Likes

C# LAB at HoM 4..

David is a cricket coach of a local team. He is analyzing the performance of one of his batsman. For this, he wants a program that should accept the number of recent matches for which the scores of the batsman need to be analyzed. After this, the program should accept the scores of the batsman for these matches, and then display the scores in ascending order. Help David create the program. Hint: Declare an integer array with a maximum capacity of 100 elements. (Duration: 40 min)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//Sorting of a Number
namespace chapter4
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = new int[100];
            Console.Write("Enter the number of recent matches for which the scores of the batsman need to be analyzed:");
            string s = Console.ReadLine();
            int x = Int32.Parse(s);

            Console.WriteLine("======================");
            Console.WriteLine("Enter the scores:");
            Console.WriteLine("======================");
            for (int j = 0; j < x; j++)
            {
                string s1 = Console.ReadLine();
                a[j] = Int32.Parse(s1);
            }
            int limit = x - 1;
            for (int pass = 0; pass < x - 1; pass++)
            {
                for (int j = 0; j < limit -pass; j++)
                {
                    if (a[j] > a[j + 1])
                    {
                        int k = a[j];
                        a[j] = a[j + 1];
                        a[j + 1] = k;

                    }
                }
            }
            Console.WriteLine("========================================================");
            Console.WriteLine("Scorted scores of the batsman are:");
            for (int j = 0; j < x; j++)
                Console.WriteLine(a[j]);
            Console.ReadLine();
        }
    }
}





Write a program to identify whether the number entered by a user is even or odd. (Duration: 40 min)


using System;
class EvenOddNumber
{
static void Main (string [] args)
{
int Number;
Console.WriteLine("Enter the number to be checked as Even or Odd");
Number = Convert.ToInt32(Console.ReadLine());
if (Number % 2 == 0)
{
Console.WriteLine(" The number you have entered is an Even number");
}
else
{
Console.WriteLine("The number you need entered is an Odd number");
}
Console.ReadLine();
}
}

No comments: