First of all, learn how to indent code. One space isn't enough. Most people go for 2 or 4 spaces.
Code:
#include<stdio.h>
int main()
{
int i, a[60], val, find = -1;
//clrscr();
for (i = 0; i < 5; i = i + 1) {
printf("\nenter value of index[%d]:", i);
scanf("%d", &a[i]);
}
for (i = 0; i < 5; i = i + 1) {
printf("\nvalue of array a[%d]:%d", i, a[i]);
}
printf("\nEnter value to search:");
scanf("%d", &val);
for (i = 0; i < 5; i = i + 1) {
if (val == a[i]) {
find = i;
break;
}
}
if (find > -1) // here used -1 bcz value can be found at index 0 so 0 will be stored in var find.
{
printf("found value in index:%d", find);
} else {
printf("value not found");
}
//getch();
return 0;
}
You've already been told about the void main thing, so please stop doing it.
Your find variable is uninitialised, so you need to fix that
Code:
$ ./a.out
enter value of index[0]:2
enter value of index[1]:3
enter value of index[2]:4
enter value of index[3]:6
enter value of index[4]:8
value of array a[0]:2
value of array a[1]:3
value of array a[2]:4
value of array a[3]:6
value of array a[4]:8
Enter value to search:1
found value in index:32647$
> printf("\nEnter value to search:");
> printf("value not found");
The usual convention is to put \n at the end of every printf call to ensure that the line is seen.