Skip to content

Instantly share code, notes, and snippets.

@Dbhardwaj99
Created January 10, 2022 07:01
Show Gist options
  • Save Dbhardwaj99/6a17b02b706e4602143a641391a8f520 to your computer and use it in GitHub Desktop.
Save Dbhardwaj99/6a17b02b706e4602143a641391a8f520 to your computer and use it in GitHub Desktop.
#include<stdio.h>
int i,l;
int search(int ,int *,int);
int main(){
int n,m;
printf("enter the size of array:");
scanf("%d",&n);
int a[n];
printf("enter the elements:\n");
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
printf("enter the element to be searched:");
scanf("%d",&m);
search(n,a,m);
return 0;
}
int search(int n,int *a,int m){
for(i=0;i<n;i++){
if(m==a[i]){
l=1;
break;
}
}
if(l==1){
printf("%d is present in the array",m);
} else {
printf("%d is not present in the array",m);
}
}
@Dbhardwaj99
Copy link
Author

Dbhardwaj99 commented Jan 10, 2022

#include<stdio.h>
int i,l;
int main(){
int n,m;
printf("enter the size of array:");
scanf("%d",&n);
int a[n];
int *p = a;
printf("enter the elements:\n");
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
printf("enter the element to be searched:");
scanf("%d",&m);
for(i=0;i<n;i++){
if(p[i]==m){
l=1;
break;
}
}
if(l==1){
printf("%d is present in the array",m);
} else {
printf("%d is not present in the array",m);
}
return 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment