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();
}
}
}
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();
}
}
}
No comments:
Post a Comment