Skip to content

Commit

Permalink
Added basic DMA
Browse files Browse the repository at this point in the history
  • Loading branch information
Ujjwal Kumar authored Oct 2, 2020
1 parent c78425a commit f846de4
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions DMA.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,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));
}

0 comments on commit f846de4

Please sign in to comment.