爱问知识人 爱问教育 医院库

用c 编程 在一维数组中查找用户给定的数据

首页

用c++编程 在一维数组中查找用户给定的数据

用c++编程   在一维数组中查找用户给定的数据,如果找到输出找到,如果没找到,输出没找到

提交回答
好评回答
  • 2008-11-07 17:05:00
    int Find(int a[],int n,int target){ int leap=0; for(int i=0;i<n;i++)  if(a[i]==target)  {leap=1;break;} return leap;}#include<iostream.h>void main(){ int *p,n,target,leap; cin>>n>>target; p=new int[n]; for(int i=0;i<n;i++)  cin>>p[i]; leap=Find(p,n,target); if(leap==1)cout<<"找到"<<endl; else cout<<"没找到"<<endl;}

    蔡***

    2008-11-07 17:05:00

其他答案

    2008-11-06 15:19:00
  •   我不知道你那数据是什么类型的,也不清楚要找的数据又是什么类型的,我写了一个在指定字符数组中查找字符的一个简单的小程序,希望对你有帮助#include <iostream。h>#include <string。
      h>void main(){ int search(char s[],char c),rs; char s[]="I am happy",c='m'; rs=search(s,c); if(rs==1) cout<<"Found"<<endl; else cout<<"Not Found"<<endl;}int search(char s[],char c){ unsigned int i; for(i=0;i<strlen(s);i++) { if(s[i]==c) return 1; } return 0;}。

    d***

    2008-11-06 15:19:00

  • 2008-11-06 09:56:00
  • #include<iostream>using namespace std;int main(){    if(找到了)        cout<<"找到了";    else        cout<<"没找到";    return 0;}

    l***

    2008-11-06 09:56:00

  • 2008-11-06 09:02:00
  • 举个例子:#include<iostream>using namespace std;int main(){ int a[10]={9,12,15,4,6,7,3,10,8,2},biaozhi=0; cout<<"Enter a number: "; int b; cin>>b; for(int i=0;i<10;i++) {  if(b==a[i])   cout<<"找到"<<endl;  else   biaozhi++; } if(biaozhi!=0)  cout<<"没找到"<<endl; return 0;}

    l***

    2008-11-06 09:02:00

相关推荐

正在加载...
最新问答 推荐信息 热门专题 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):