Skip to content

Instantly share code, notes, and snippets.

@sachendra003
Created January 1, 2018 16:26
Show Gist options
  • Save sachendra003/62b1189ef4f8dc8963ff69ba81609f0a to your computer and use it in GitHub Desktop.
Save sachendra003/62b1189ef4f8dc8963ff69ba81609f0a to your computer and use it in GitHub Desktop.
C program to Find Index of Array #1
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a[]={1,3,4,5,7,8,9,45,11,65,2,6};
int num,i,p,c=0;
int n=sizeof(a)/sizeof(a[0]);
printf("Enter a value :\n");
scanf("%d",&num);
for(i=0;i<n;i++)
{
if(a[i]==num)
{
p=i;
printf("Element index is %d",p);
c=1;
break;
}
else
{
c=0;
}
if(c==0)
{
// printf("Number is not in Array: \n");
}
}
}
@jun447
Copy link

jun447 commented Jan 10, 2021

if(c==0)
{
printf("Number is not in Array: \n");

    }

place this outside for loop

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