Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace _04.HowManyTimes
- {
- class Program
- {
- static int[] myArray = new int[20];
- static void Main(string[] args)
- {
- GenerateRandomMatrix();
- for (int i = 0; i < myArray.Length; i++)
- {
- Console.WriteLine("Value {0} is appears {1} times", myArray[i], CountTimes(myArray[i]));
- }
- }
- private static int CountTimes(int element)
- {
- int count=0;
- for (int i = 0; i < myArray.Length; i++)
- {
- if (element == myArray[i])
- {
- count++;
- }
- }
- return count;
- }
- private static void GenerateRandomMatrix()
- {
- Random randomNumber = new Random();
- for (int i = 0; i < myArray.Length; i++)
- {
- myArray[i] = randomNumber.Next(11); //generate random number between 0 and 10
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement