//This program is about finding the index value of array elements.
#include<stdio.h>Output
#include<conio.h>
int main()
{
int list[100],n,i,s,p;
printf("Enter the size of list");//enter array size limit
scanf("%d",&n);
printf("Enter the elements\n");
for(i=0;i<n;i++)
scanf("%d",&list[i]);
p=0;//initialize p to zero
printf("\nEnter the element to be search");//searching array element for finding index value
scanf("%d",&s);
for(i=0;i<n;i++)
{
if(list[i]==s)
{
p=i;//assigning the index value to p
}
}
if(p>=0)//index of array value is greater or equal to zero
printf("Index value of %d is %d",s,p);
else
printf("Try again");
getch();
}

No comments:
Post a Comment
Note: only a member of this blog may post a comment.