1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
#include<iostream>
using namespace std;
int main()
{
int num[20]={23,45,1,23,5,78,6,13,1,4,78,18,3,5,26,4,5,10,3,45};
int search,c,n,big,small;
float m,oc;
//search the item in the array
cout<<"Enter the number to search\n";
cin>>search;
while(search>0)
{
m=search%10;
if(m==c)
oc++;
search=search/10;
}//show the occurrence
cout<<"Digit occurred "<<oc<<" times";
//show respective array locations
for(c=0; c<20; c++)
{
if(num[c]==search)
{
cout<<search<<" is present at location"<<c+1;
break;
}
}
//show the largest and the smallest element
if(c==num[20])
{
big=num[0];
for(c=1; c<num[20]; c++)
{
if(big<num[c])
{
big=num[c];
}
}
cout<<"Largest element : "<<big;
small=num[0];
for(c=1; c<num[20]; c++)
{
if(small>num[c])
small=num[c];
}
cout<<"Smallest element : "<<small;
}
return 0;
}
|