Skip to content

Commit 47d0958

Browse files
Merge pull request #170 from nivanjanapramod/master
Create MostFrequentWordInString.c
2 parents dc895e2 + 5393c3c commit 47d0958

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

MostFrequentWordInString.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include <iostream>
2+
#include <string>
3+
4+
using namespace std;
5+
6+
int main()
7+
{
8+
cout << "Value of inputs in your array?" << endl;
9+
int arraysize;
10+
cin >> arraysize;
11+
12+
cout << "Input array elements:" << endl;
13+
14+
string array[arraysize];
15+
16+
for(int i=0; i<arraysize; i++)
17+
{
18+
cin >> array[i];
19+
}
20+
21+
int most_occur = 1;
22+
23+
for(int i=0; i<arraysize-1; i++)
24+
{
25+
int times_occur = 1;
26+
27+
for(int j=i+1; j<arraysize; j++)
28+
{
29+
if(array[i]==array[j])
30+
times_occur = times_occur + 1;
31+
}
32+
33+
if(times_occur>most_occur)
34+
{
35+
most_occur = times_occur;
36+
}
37+
38+
}
39+
40+
if(most_occur>1)
41+
{
42+
cout << "Most occuring: ";
43+
for(int i=0; i<arraysize-1; i++)
44+
{
45+
int times_occur = 1;
46+
47+
for(int j=i+1; j<arraysize; j++)
48+
{
49+
if(array[i]==array[j])
50+
times_occur = times_occur + 1;
51+
}
52+
53+
if(times_occur==most_occur)
54+
{
55+
cout << array[i] << " ";
56+
}
57+
}
58+
}
59+
60+
else
61+
{
62+
cout << "No specific array elements are repeating.";
63+
}
64+
65+
return 0;

0 commit comments

Comments
 (0)