-
Notifications
You must be signed in to change notification settings - Fork 18
/
Find the Maximum Frequency of values entered and print the each number frequency.cs
103 lines (93 loc) · 3.08 KB
/
Find the Maximum Frequency of values entered and print the each number frequency.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication53
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Counting Number of Occurences of an Character");
int i, j, N, k = 0, count = 1,l=0,sum=0,C=0,Maximum=0,m=0;
Console.WriteLine("Enter the Maximum Range of the Array");
N = Convert.ToInt32(Console.ReadLine());
int[] a = new int[N];
int[] search = new int[N];
int[] freq = new int[N];
search[k] = -1;
Console.WriteLine("Enter the input values to the array");
for (i = 0; i <= N-1; i++)
{
a[i] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("The values entered are:");
for (i = 0; i <= N-1; i++)
{
Console.Write("{0} ", a[i]);
}
Console.WriteLine("\n");
for (i = 0; i < N-1; i++)
{
for (j = 0; j < N-1;j++ )
{
if (a[j] == a[j + 1])
{
count++;
search[k] = a[j];
freq[l] = count;
}
else
{
search[k] = a[j];
freq[l] = count;
k++;
l++;
C++;
count = 1;
}
search[k] = a[j+1];
freq[l] = count;
}
break;
}
Console.WriteLine("To Find the Maximum Occurence of an Character");
for (l = 0; l <= C;l++)
{
for (i = 0; i<= C; i++)
{
if (freq[i] > freq[i + 1])
{
Maximum = freq[i];
m = i;
}
}
Console.WriteLine("\n");
Console.WriteLine("Maximum={0}",Maximum);
Console.WriteLine("\n");
break;
}
for (k= 0; k <=C; k++)
{
for(l=0;l<=C;l++)
{
if (k == l)
{
Console.WriteLine("The Given character {0} appears {1} times", search[k], freq[l]);
}
if (k == l&&k==m)
{
Console.WriteLine("The given character {0} appears Maximum of {1} times", search[k], freq[l]);
break;
}
}
if (sum == N)
{
break;
}
}
Console.ReadLine();
}
}
}