Write a program that takes n numbers and displays the most repeated number.
please write it in c #
Answers
Answer:
//C# program to find the maximum repeating
// number
using System;
class GFG {
// Returns maximum repeating element
// in arr[0..n-1].
// The array elements are in range
// from 0 to k-1
static int maxRepeating(int []arr,
int n, int k)
{
// Iterate though input array, for
// every element arr[i], increment
// arr[arr[i]%k] by k
for (int i = 0; i< n; i++)
arr[(arr[i]%k)] += k;
// Find index of the maximum
// repeating element
int max = arr[0], result = 0;
for (int i = 1; i < n; i++)
{
if (arr[i] > max)
{
max = arr[i];
result = i;
}
}
// Return index of the
// maximum element
return result;
}
/*Driver function to check for
above function*/
public static void Main ()
{
int []arr = {2, 3, 3, 5, 3, 4, 1, 7};
int n = arr.Length;
int k=8;
Console.Write("Maximum repeating "
+ "element is: "
+ maxRepeating(arr,n,k));
}
}