-
Notifications
You must be signed in to change notification settings - Fork 24
/
array_adt.c
46 lines (39 loc) · 917 Bytes
/
array_adt.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
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<time.h>
#include<stdlib.h>
struct myarray{
int total_size;
int used_size;
int *ptr;
}marks;
void createarray(struct myarray* a, int tsize, int usize){
// (*a).total_size = tsize;
// (*a).used_space = usize;
// (*a).ptr = (int *)malloc(tsize*sizeof(int));
a->total_size = tsize;
a->used_size = usize;
a->ptr = (int *)malloc(tsize*sizeof(int));
}
void show(struct myarray *a){
int i =0;
for(i=0;i< a->used_size ;i++){
printf("%d\n",(a->ptr)[i]);
}
}
void setval(struct myarray *a){
int i =0,n;
for(i=0;i< a->used_size ;i++){
printf("enter element %d ",i);
scanf("%d",&n);
(a->ptr)[i] = n;
}
}
int main(){
struct myarray;
createarray(&marks,10,2);
setval(&marks);
show(&marks);
return 0;
}