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; }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment