"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain

Wednesday, February 10, 2010

Write a program to store 20 integers in an array. Then, accept another integer value and search for that integer in the array.


#include<iostream.h>
#include<conio.h>
#include <process.h>


void main()
{
int arr[20], i;


for( i= 0; i< 20 ; i++)
{cout<< "\n Enter an element :";
cin >> arr[i];
}


int x;


cout<<" \n Enter an element to be searched for :";
cin>> x;


for(i = 0; i< n ; i++)
{
if(x == arr[i])
{
cout<<" \n The element is found in position : " << i+1;
getch();
exit(1);
}
}


cout<< "\n The element not found ";
getch();
}

No comments:

Post a Comment

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.