Created
January 1, 2018 16:26
-
-
Save sachendra003/62b1189ef4f8dc8963ff69ba81609f0a to your computer and use it in GitHub Desktop.
C program to Find Index of Array #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if(c==0)
{
printf("Number is not in Array: \n");
place this outside for loop