7- Write a function that displays the frequency of occurrence of an element entered by the user in a stored array. The array always has the following elements: 4, 2, 7, 10, 9, 7, 6, 10, -8, 7, 9.
Sample Executions:
Enter a number: 7
The number 7 occurred 3 times in your array.
Press any key to continue
Enter a number:17
The number 17 occurred 0 times in your array.
Press any key to continue
1
Expert's answer
2012-11-13T10:35:25-0500
#include <iostream>
using namespace std;
int arrayofnumbers[]={4, 2, 7, 10, 9, 7, 6, 10, -8, 7, 9}; int main() { int number=0; int times=0; cout<<"Enter a number: "; cin>>number; for(int i=0;i<11;i++){ if(number==arrayofnumbers[i]){ times++; } } cout<<"The number "<<number<<" occurred "<<times<<" times in your array."; cout<<" Press any key to continue"; cin>>number; return 0; }
Finding a professional expert in "partial differential equations" in the advanced level is difficult.
You can find this expert in "Assignmentexpert.com" with confidence.
Exceptional experts! I appreciate your help. God bless you!
Comments
Leave a comment