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
#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;
}
Comments
Leave a comment