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
|
#include <conio.h>
#include <iostream.h>
main(){
int c,i,posisi;
int A[20]={3,2,4,10,20,1,5,8,7,9,6,5,11,12,14,13,16,15,17,19};
cout<<"Data : ";
for(i=0;i<20;i++){
cout<<A[i]<<" ";
}
cout<<"\n postion data to search : ";
cin>>c;
i=0;
position=0;
while(i<19 && A[i]!=c){
i++;
}
if (A[i]!=c){
cout<<"sorry your data isn't found";
}else if(position=i+1)
cout<<"discovered "<<posisi;
getch();
}
|