mirror of
https://github.com/ada-dmitry/prog.l_ada.git
synced 2026-09-24 09:10:14 +00:00
Merge branch 'master' of https://github.com/ada-dmitry/ADA
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
#include <stdio.h>
|
||||
#define N 5
|
||||
void sort_Select(int x, int *arr){
|
||||
int ind, temp = 0;
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
//meow
|
||||
void sort_insert(int l, int *arr){
|
||||
int i, j, x;
|
||||
for(i=0;i<l;i++){
|
||||
j = i-1;
|
||||
x = arr[i];
|
||||
while((arr[j]>x)&&(j>=0)){
|
||||
arr[j+1] = arr[j];
|
||||
j--;
|
||||
arr[j+1] = x;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
int main(int argc, char** argv) {
|
||||
int l,i;
|
||||
//printf("Vvedite razmer massiva: ");
|
||||
//scanf("%d", l);
|
||||
int arr[N] = {4,5,2,3,1};
|
||||
int arra[N] = {3,5,2,4,1};
|
||||
sort_Select(N, arr);
|
||||
sort_insert(N, arra);
|
||||
for(i=0;i<N;i++){
|
||||
printf("%d", arr[i]);
|
||||
}
|
||||
printf("\n");
|
||||
for(i=0;i<N;i++){
|
||||
printf("%d", arra[i]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
#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
@@ -0,0 +1,65 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user