forked from harsh2102/C
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DMA.c
32 lines (31 loc) · 773 Bytes
/
DMA.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
/*This program shows the use of
*very basic functions of Dynamic memory
*allocation in C.
*/
#include<stdio.h>
#include<stdlib.h>
int linearsearch(int *a,int n,int key)
{
int i=0;
for(int i=0;i<n;i++)
{
if(a[i]==key)
return i;
}
return -1;
}
int main()
{
int i,*a,n,key;
printf("Enter the size of array\t");
scanf("%d",&n);
a=(int*)malloc(n*sizeof(int));
//Similar function calloc can also be used
for(i=0;i<n;i++)
scanf("%d",a+i);
printf("Enter the number to be searched\t");
scanf("%d",&key);
if(linearsearch(a,n,key)==-1)
printf("Number is not present in the array\n");
else printf("Element found at index %d\n",linearsearch(a,n,key));
}