Computer Science, asked by ishfaqbisma79, 4 months ago

write pseudocode to count the occuerence of a number in the list

Answers

Answered by nikhilvidyasoudha
0

Answer:

Explanation:

Given number in & Write pseudo code to count occurrence of a given number in the list for example, consider the following list, if user enters 5Given number in & Write pseudo code to count occurrence of a given number in the list for example, consider the following list, if user enters 5

Answered by abhilash7995
0

Answer:

// C++ program to count occurrences of an element

#include<bits/stdc++.h>

using namespace std;

// Returns number of times x occurs in arr[0..n-1]

int countOccurrences(int arr[], int n, int x)

{

int res = 0;

for (int i=0; i<n; i++)

if (x == arr[i])

res++;

return res;

}

// Driver code

int main()

{

int arr[] = {1, 2, 2, 2, 2, 3, 4, 7 ,8 ,8 };

int n = sizeof(arr)/sizeof(arr[0]);

int x = 2;

cout << countOccurrences(arr, n, x);

return 0;

}

Similar questions