A blog to help students to learn programming in various languages including C, C++, Java, Python and many more.

Subscribe For Free Latest Updates!

We'll not spam mate! We promise.

Thursday 18 February 2016


ScreenShot
Output

#include <iostream>
using namespace std;
int search(int *a,int x,int n);
int main()
{
int loc,n,data,a[100];
cout<<"Enter no. of values: ";
cin>>n;
cout<<"Enter "<<n<<" values: ";
for(int x=0;x<n;x++) {
cin>>a[x];
}
cout<<"Entered array is: "<<"\n";
for(int x=0;x<n;x++) {
cout<<a[x]<<"  ";
}
cout<<"\nEnter element you want to delete: ";
cin>>data;
loc=search(&a[0],data,n);
if ( loc== -1 ) {
cout<<"Entered element is not present in array.";
} else {
for(int x=loc;x<n-1;x++) {
a[x]=a[x+1];
}
cout<<"Array after deletion:"<<"\n";
for(int x=0;x<n-1;x++) {
cout<<a[x]<<"  ";
}
}
return(0);
}

int search(int *a,int data,int n)
{
for(int x=0;x<n;x++) {
if(data==a[x]) {
return(x);
}
}
return(-1);
}

Read More >>


Copyright © 2016 - ProgrmIt - All Rights Reserved
(Articles Cannot Be Reproduced Without Author Permission.)
Design By : | Powered By: Blogger