This C++ program asks the user to input the size of an array, then populate the array with values. It then prompts the user for a number to search for within the array. The program iterates through the array, counting each time the search number is found. It outputs the number of occurrences of the search number in the array.
This C++ program asks the user to input the size of an array, then populate the array with values. It then prompts the user for a number to search for within the array. The program iterates through the array, counting each time the search number is found. It outputs the number of occurrences of the search number in the array.
This C++ program asks the user to input the size of an array, then populate the array with values. It then prompts the user for a number to search for within the array. The program iterates through the array, counting each time the search number is found. It outputs the number of occurrences of the search number in the array.
int v[100],i,n,x,nr; int main()//Numarul de aparitii al unui element intr-un vector { cout<<"Dati n:"; cin>>n; for(i=1;i<=n;i++) cin>>v[i]; cout<<"Dati un numar:"; cin>>x; for(i=1;i<=n;i++) { if(v[i]==x) nr++; } cout<<"Numarul apare de "<<nr<<" ori in vector"; }