Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int getOccurrence(int arr[], int size, int num) {
- int count(0);
- for (int i = 0; i < size; i++) {
- if (num == arr[i])
- count++;
- }
- return count;
- }
- int main() {
- int array[100], size(0), num(0); int times = 0;
- cout << "Enter the size of the array!\n";
- cin >> size;
- cout << "Enter your array\n";
- for (int i = 0; i < size; i++) {
- cin >> array[i];
- }
- cout << "Enter the number you want to calculate how many times it occurred in the array\n";
- cin >> num;
- times= getOccurrence(array, size, num);
- cout << "The number of times the number " << num << " occurred is " << times << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement