Skip to content

Commit

Permalink
Merge pull request #170 from nivanjanapramod/master
Browse files Browse the repository at this point in the history
Create MostFrequentWordInString.c
  • Loading branch information
gouravthakur39 committed Jun 25, 2022
2 parents dc895e2 + 5393c3c commit 47d0958
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions MostFrequentWordInString.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include <iostream>
#include <string>

using namespace std;

int main()
{
cout << "Value of inputs in your array?" << endl;
int arraysize;
cin >> arraysize;

cout << "Input array elements:" << endl;

string array[arraysize];

for(int i=0; i<arraysize; i++)
{
cin >> array[i];
}

int most_occur = 1;

for(int i=0; i<arraysize-1; i++)
{
int times_occur = 1;

for(int j=i+1; j<arraysize; j++)
{
if(array[i]==array[j])
times_occur = times_occur + 1;
}

if(times_occur>most_occur)
{
most_occur = times_occur;
}

}

if(most_occur>1)
{
cout << "Most occuring: ";
for(int i=0; i<arraysize-1; i++)
{
int times_occur = 1;

for(int j=i+1; j<arraysize; j++)
{
if(array[i]==array[j])
times_occur = times_occur + 1;
}

if(times_occur==most_occur)
{
cout << array[i] << " ";
}
}
}

else
{
cout << "No specific array elements are repeating.";
}

return 0;

0 comments on commit 47d0958

Please sign in to comment.