Write a program that finds in a given array of integers (in the range
[0…1000]) how many times each of them occurs.
Example: array = {3, 4, 4, 2, 3, 3, 4, 3, 2}Chapter 16. Linear Data Structures 677
2 2 times
3 4 times
4 3 times
using System;
using System.Linq;
namespace ConsoleApplication8
{
class Program
{
static void Main()
{
int[] source = new int[] { 1, 2, 2, 3, 3, 3, 4, 5, 6, 7 };
foreach (var item in source.Distinct())
{
Console.WriteLine("{0} => {1} Times",item,source.Count(f => f == item));
}
Console.ReadLine();
}
}
}
[0…1000]) how many times each of them occurs.
Example: array = {3, 4, 4, 2, 3, 3, 4, 3, 2}Chapter 16. Linear Data Structures 677
2 2 times
3 4 times
4 3 times
using System;
using System.Linq;
namespace ConsoleApplication8
{
class Program
{
static void Main()
{
int[] source = new int[] { 1, 2, 2, 3, 3, 3, 4, 5, 6, 7 };
foreach (var item in source.Distinct())
{
Console.WriteLine("{0} => {1} Times",item,source.Count(f => f == item));
}
Console.ReadLine();
}
}
}