This commit is contained in:
ada-dmitry
2023-03-20 14:53:30 +03:00
parent fbe383f94f
commit 62fabb30d9
4 changed files with 57 additions and 5 deletions
+33
View File
@@ -0,0 +1,33 @@
#include<stdio.h>
#include<stdlib.h>
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; i<n; i++){
printf("Enter name %d: ", i+1);
scanf("%s", &(person+i)->name);
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; i<n; i++){
printf("Name: %s\n Age: %d\n Salary: %.2f\n", (person+i)->name, (person+i)->age, (person+i)->salary);
}
free(person);
return 0;
}
+23 -4
View File
@@ -2,11 +2,27 @@
#include<stdlib.h> #include<stdlib.h>
#include<time.h> #include<time.h>
#include<error.h> #include<error.h>
#define N 5
struct st1{ struct st1{
int i; int i;
char s[128]; 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){ void st_rand(struct st1 temp[], int n){
int k; int k;
int j; int j;
@@ -31,15 +47,18 @@ void st_print(struct st1 temp[], int n){
} }
} }
int main(int argc, char *argv[]){ int main(int argc, char *argv[]){
int alenght;
printf("input n = ");
scanf("%d", &alenght);
struct st1 *pq=NULL; struct st1 *pq=NULL;
srand(time(NULL)); srand(time(NULL));
if((pq=malloc(N*sizeof(struct st1))) == NULL){ if((pq=malloc(alenght*sizeof(struct st1))) == NULL){
printf("malloc: NULL\n"); printf("malloc: NULL\n");
exit(2); exit(2);
} }
st_rand(pq,N); st_rand(pq,alenght);
st_print(pq,N); st_print(pq,alenght);
free(pq); free(pq);
pq = NULL; pq = NULL;
return 0; return 0;
Binary file not shown.
Binary file not shown.