Answer to Question #339453 in C++ for Dan

Question #339453

Write a program using one dimensional arrays that searches a number and display the number of times it occurs on the list of 12 input values

1
Expert's answer
2022-05-11T08:48:55-0400





#include <iostream>
using namespace std;
int main()
{
  int array[12];
  double sum=0;
  for(int i=0;i<12;i++)
    {
      cout<<"["<<i+1<<"]=";
      cin>>array[i];
    }
  int key;
  cout<<"Input key for search:";
  cin>>key;
  
  cout<<"Start searching .....\n";
  int fr=0;
  for(int i=0;i<12;i++)
    {
      if(array[i]==key)
      {
        cout<<"Found index:="<<i<<endl;   
        fr++;
      }
    }
  if(fr==0)
    cout<<"Not found\n";
  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS