补、C++第八次上机实验

//test5  在包含10个数的一维整数数组a中查找给定的数据num。 如果找到则返回1,未找到返回 0 .
#include <fstream.h>
#include <iostream.h>
int fun(int a[],int num)
{
/**********Program**********/
int n=0;
for(int i=0;i<10;i++)
{
	if(num==a[i])
		n=1;
	
}
return n;


/**********  End  **********/
}
void main()
{
    
       int a[10]={54,256,563,754,34,56,345,543,45,65};
       int num = 46;
           if (fun(a,num)==1)
                        cout <<" 找到!" <<endl;
           else
            cout <<" 没有找到!" <<endl;
           void wwjt();
           wwjt();
}
void wwjt()
{
      int a[10]={54,256,563,754,34,56,345,543,45,65};
          
                fstream myfile;
                myfile.open(" out.txt" ,ios::out);
                myfile<<fun(a,46)<<endl;
                myfile<<fun(a,345)<<endl;
                myfile.close();
}

心得体会:利用for循环查找数组中的数据

猜你喜欢

转载自blog.csdn.net/qq_34143673/article/details/51700636