Computer Science, asked by zfgulzar, 30 days ago

Anyone plz help me urgently...!!
Both d programs must be in Java....
Q1) WAP to accept an integer array and print the frequency of numbers in it.
Q2) WAP to accept a number N. Then print the frequency of digit in it.​

Answers

Answered by samairaaggarwal4
0

Answer:

Input: N = 1122322  ,  D = 2

Output: 4

Input: N = 346488  ,  D = 9

Output: 0

Explanation:

Answered by ushap787
1

Answer:

Given an array a[] and an element x, find number of occurrences of x in a[].

Examples:

Input : a[] = {0, 5, 5, 5, 4}

x = 5

Output : 3

Input : a[] = {1, 2, 3}

x = 4

Output : 0

The idea is simple, we initialize count as 0. We traverse array in linear fashion. For every element that matches with x, we increment count. Finally we return count.

Below is the implementation of the approach.

// CPP program to count occurrences of an

// element in an unsorted array

#include<iostream>

using namespace std;

int frequency(int a[], int n, int x)

{

int count = 0;

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

if (a[i] == x)

count++;

return count;

}

// Driver program

int main() {

int a[] = {0, 5, 5, 5, 4};

int x = 5;

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

cout << frequency(a, n, x);

return 0;

}

Explanation:

I hope this answer will help you

PLEASE MAKE ME AS A BRAINLIST

Similar questions