-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program16_2.c
63 lines (47 loc) · 1021 Bytes
/
Program16_2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include<stdio.h>
#include<stdlib.h>
int Index(int Arr[], int iSize, int iValue)
{
int iCnt = 0, iDig = 0;
for(iCnt = 0; iCnt < iSize; iCnt++)
{
if(Arr[iCnt] == iValue)
{
iCnt = iDig;
}
}
if(iDig = iSize)
{
return -1;
}
else
{
return iDig;
}
}
int main()
{
int iLength = 0, i = 0;
int iRet =0;
int *ptr = 0;
int iNo = 0;
printf("Enter number of elements\n");
scanf("%d",&iLength);
ptr = (int *)malloc(iLength * sizeof(int));
printf("Enter numbers\n");
for(i = 0; i <iLength; i++)
{
scanf("%d",&ptr[i]);
}
printf("Enter a number want to check\n");
scanf("%d",&iNo);
iRet = Index(ptr, iLength, iNo);
if(iRet == -1)
{
printf("%d is not present in the array \n", iNo);
}
else
{printf("The index of %d is %d",iNo, iRet);}
free(ptr);
return 0;
}