File tree Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Original file line number Diff line number Diff line change 1
1
#include <stdio.h>
2
-
2
+ #include <stdlib.h>
3
3
int main ()
4
4
{
5
- int array [ 100 ] , search , c , n ;
5
+ int * array , search , c , n_terms ;
6
6
7
7
printf ("Enter the number of elements in array\n" );
8
- scanf ("%d" ,& n ); // Total no of elements
8
+ scanf ("%d" ,& n_terms ); // Total no of elements
9
9
10
- printf ("Enter %d integer(s)\n" , n );
10
+ array = (int * )malloc (sizeof (int )* n_terms );
11
+ printf ("Enter %d integer(s)\n" , n_terms );
11
12
12
- for (c = 0 ; c < n ; c ++ )
13
+ for (c = 0 ; c < n_terms ; c ++ )
13
14
scanf ("%d" , & array [c ]); // Reading the elements
14
15
15
16
printf ("Enter the number to search\n" ); // Target element to be searched
16
17
scanf ("%d" , & search );
17
18
18
- for (c = 0 ; c < n ; c ++ )
19
+ for (c = 0 ; c < n_terms ; c ++ )
19
20
{
20
21
if (array [c ] == search ) /* if required element found */
21
22
{
22
23
printf ("%d is present at location %d.\n" , search , c + 1 );
23
24
break ;
24
25
}
25
26
}
26
- if (c == n )
27
+ if (c == n_terms )
27
28
printf ("%d is not present in array.\n" , search ); // Element not found
28
29
29
30
return 0 ;
You can’t perform that action at this time.
0 commit comments