Size of array is taken from user.. Elements are entered.. Then user is asked to enter element to be searched.. Search is performed..
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
- #include<iostream.h>
- #include<conio.h>
- void main()
- {
- clrscr();
- int ar[10],n,num,no;
- cout<<"Enter size of the array: ";
- cin>>n;
- cout<<"Enter array element: "<<endl;
- for(int i=0;i<n;i++)
- {
- cout<<"Enter element "<<i<<": ";
- cin>>ar[i];
- }
- //Coding by: Snehil Khanor
- //http://WapCPP.blogspot.com
- cout<<"Elements of array: "<<endl;
- for(i=0;i<n;i++)
- cout<<"Element at index number "<<i<<" is: "<<ar[i]<<endl;
- //////To search////
- cout<<"Enter number to search: ";
- cin>>num;
- for(i=0;i<n;i++)
- {
- if(num==ar[i])
- {
- cout<<"Found at index number: "<<i;
- no=0;
- break;
- }
- else
- {
- no=1;
- continue;
- }
- }
- if(no==1)
- cout<<"Sorry your search returned NO results. :(";
- getch();
- }
1 comments:
there is a mistake in this program .
in this program u declared array with 10 size and then during program u again want size of array.
2ndly this may take values from user because of loop but when it cout the array it print numbers declared with in array size and values which is store in index number great then initialy declared size.its print the random values to that index number .hope u understand.03008526184.my number
Post a Comment