Skip to content

Create MostFrequentWordInString.c #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;