Created
January 1, 2018 16:59
-
-
Save sachendra003/69cdc458bb061b789adc919d876fbe9d to your computer and use it in GitHub Desktop.
C Program to Find index of Array
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() | |
{ | |
char a[]={'a','b','c','d'}; | |
int i,p,c=0; | |
char num; | |
int n=sizeof(a)/sizeof(a[0]); | |
printf("Enter a character :\n"); | |
scanf("%c",&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