This commit is contained in:
ada-dmitry
2023-03-26 11:05:27 +03:00
parent 78387c208f
commit 522f0d0aea
27 changed files with 7 additions and 0 deletions
-11
View File
@@ -1,11 +0,0 @@
#include "st_func.h"
#define N 5
int main(int argc, char *argv[]){
struct st1 q[N];
st_rand(q,N);
st_print(q,N);
return 0;
}
Binary file not shown.
-8
View File
@@ -1,8 +0,0 @@
struct st1{
int i;
char s[128];
};
void st_rand(struct st1 temp[], int n);
void st_print(struct st1 temp[], int n);
-24
View File
@@ -1,24 +0,0 @@
#include<stdio.h>
#include<stdlib.h>
#include "st_func.h"
void st_rand(struct st1 temp[], int n){
int k;
int j;
srand(time(NULL));
for(k=0; k<n; k++){
(temp+k)->i = rand()%100;
for(j=0;j<127;j++){
(temp+k)->s[j]=((char)(65+rand()%25));
}
(temp+k)->s[127]='\0';
}
}
void st_print(struct st1 temp[], int n){
int k;
for(k=0;k<n;k++){
printf("%d->[%2d][%s]\n", k, temp[k].i, (temp+k)->s);
}
}
-8
View File
@@ -1,8 +0,0 @@
struct st1{
int i;
char s[128];
};
void st_rand(struct st1 temp[], int n);
void st_print(struct st1 temp[], int n);
-33
View File
@@ -1,33 +0,0 @@
#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;
}
-43
View File
@@ -1,43 +0,0 @@
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void swap(int a[], int c, int d, int n){
int temp;
if((c>=n) || (d>=n)) return;
temp = a[c];
a[c] = a[d];
a[d] = temp;
}
void pa(int a[], int n){
int i;
for(i=0;i<n;i++){
printf("a[%d] = %2d ", i, a[i]);
}
printf("\n");
}
void init(int *a, int n){
srand(time(NULL));
while(n--){
*(a++)=rand()%100;
}
}
int main2(int n){
int a[n];
init(a,n);
pa(a,n);
swap(a,1,4,n);
pa(a,n);
return 0;
}
int main(){
int alenght;
printf("input n = ");
scanf("%d", &alenght);
return main2(alenght);
}
-65
View File
@@ -1,65 +0,0 @@
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<error.h>
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;
for(k=0; k<n; k++){
(temp+k)->i = rand()%100;
for(j=0;j<127;j++){
(temp+k)->s[j]=((char)(65+rand()%25));
}
(temp+k)->s[127]='\0';
}
}
/*void swap(struct st1 temp[], int c, int d, int n){
Дописать функцию!
}
*/
void st_print(struct st1 temp[], int n){
int k;
for(k=0;k<n;k++){
printf("%d->[%2d][%s]\n", k, temp[k].i, (temp+k)->s);
}
}
int main(int argc, char *argv[]){
int alenght;
printf("input n = ");
scanf("%d", &alenght);
struct st1 *pq=NULL;
srand(time(NULL));
if((pq=malloc(alenght*sizeof(struct st1))) == NULL){
printf("malloc: NULL\n");
exit(2);
}
st_rand(pq,alenght);
st_print(pq,alenght);
free(pq);
pq = NULL;
return 0;
}