diff --git a/Lesson/14.03/dz2.c b/Lesson/14.03/dz2.c new file mode 100644 index 0000000..e4c75cf --- /dev/null +++ b/Lesson/14.03/dz2.c @@ -0,0 +1,33 @@ +#include +#include + +struct list { + char name[20]; + int age; + float salary; +}; + +int main(){ + struct list *person; + int i, n = 2; + person = malloc(n*sizeof(struct list)); + + for(i = 0; iname); + + printf("Enter age %d: ", i+1); + scanf("%d", &(person+i)->age); + + printf("Enter salary %d: ", i+1); + scanf("%f", &(person+i)->salary); + } + + for(i=0; iname, (person+i)->age, (person+i)->salary); + + } + free(person); + return 0; + +} \ No newline at end of file diff --git a/Lesson/14.03/l2.c b/Lesson/14.03/l2.c index 933a428..06d8b80 100644 --- a/Lesson/14.03/l2.c +++ b/Lesson/14.03/l2.c @@ -2,11 +2,27 @@ #include #include #include -#define N 5 struct st1{ int i; char s[128]; }; +/* +void sort_Select(int x, struct st1 ){ + struct st1 temp; + int i,j; + for(i=0;i<(x-1);i++){ + ind = i; + for(j=i+1;jarr[j]){ + ind = j; + } + } + temp = arr[i]; + arr[i] = arr[ind]; + arr[ind] = temp; + } +} +*/ void st_rand(struct st1 temp[], int n){ int k; int j; @@ -31,16 +47,19 @@ void st_print(struct st1 temp[], int n){ } } int main(int argc, char *argv[]){ + int alenght; + printf("input n = "); + scanf("%d", &alenght); struct st1 *pq=NULL; srand(time(NULL)); - if((pq=malloc(N*sizeof(struct st1))) == NULL){ + if((pq=malloc(alenght*sizeof(struct st1))) == NULL){ printf("malloc: NULL\n"); exit(2); } - st_rand(pq,N); - st_print(pq,N); + st_rand(pq,alenght); + st_print(pq,alenght); free(pq); pq = NULL; return 0; -} \ No newline at end of file +} diff --git a/Lesson/14.03/output/dz2.exe b/Lesson/14.03/output/dz2.exe new file mode 100644 index 0000000..280bfbd Binary files /dev/null and b/Lesson/14.03/output/dz2.exe differ diff --git a/Lesson/14.03/output/l2.exe b/Lesson/14.03/output/l2.exe index 6429fd8..eea20cb 100644 Binary files a/Lesson/14.03/output/l2.exe and b/Lesson/14.03/output/l2.exe differ