mirror of
https://github.com/ada-dmitry/prog.l_ada.git
synced 2026-09-24 09:10:14 +00:00
dz22
This commit is contained in:
+24
-5
@@ -2,11 +2,27 @@
|
||||
#include<stdlib.h>
|
||||
#include<time.h>
|
||||
#include<error.h>
|
||||
#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;j<x;j++){
|
||||
if(arr[ind]>arr[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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user