请帮我修改或改进程序,因为它有一个逻辑错误。
编写一个程序,将在数组 num[20]={23,45,1,23,5,78,6,13,1,4,78,18,3,5,26 中搜索项的编号,4,5,10,3,45}。如果搜索项在数组中,则计算该数字在数组中出现的次数并确定它们各自的数组位置。如果搜索项不在数组中,则算法必须确定给定数组中的最大和最小元素。
这是我需要修改的代码,请帮助我...
#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;
}
这应该是输出
Enter the number to search : 23 Digit occurred : 1 23 is present at location 1 if the searched Item is not in the array Largest element : 78 Smallest element : 3
但是我的程序的输出是错误的,请帮帮我。