Compare commits

...

3 Commits

Author SHA1 Message Date
fbdb3d8b94 ыы 2024-11-21 09:47:00 +04:00
b0c6f76b47 Merge pull request 'Ветвь1' (#1) from Ветвь into main
Reviewed-on: #1
2024-11-21 09:41:59 +04:00
cd51516e1e Second 2024-11-21 09:39:54 +04:00

191
Lab
View File

@ -1,37 +1,176 @@
#include <stdio.h>
#include <Windows.h>
int strlen_my(char *s)
{
int i = 0;
char* p = s;
while (*p++) {
i++;
}
return i;
#define NUM_ELEMENTS 100
int arr[NUM_ELEMENTS];
int n = 0;
void addLastElement(int a) {
arr[n++] = a;
}
int strcpy_my(char* dest, char* src)
{
int i = 0;
while (src[i] != "\0") {
dest[i] = src[i];
i++;
void printElements() {
for (int i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
printf("\nBû ïîëó÷àåòå ñòðîêó s = \"%s\"", dest);
printf("\n");
}
int findMin() {
int min = arr[0];
for (int i = 1; i < n; i++) {
if (arr[i] < min) {
min = arr[i];
}
}
return min;
}
int findMin2() {
int min = arr[0];
int o;
for (int i = 1; i < n; i++) {
if (arr[i] < min) {
min = arr[i];
o = i;
}
}
return o;
}
int findMax() {
int max = 0;
int o;
for (int i = 1; i < n; i++) {
if (arr[i] > max && arr[i]%2==0) {
max = arr[i];
o = i;
}
}
return o;
}
void keyboardInput() {
printf("n = ");
scanf_s("%d", &n);
printf("input %d values: ", n);
for (int i = 0; i < n; i++) {
scanf_s("%d", &arr[i]);
}
}
void deleteElement(int a){
int k = n;
printf("%d", k);
for (; a < n-1; a++) {
arr[a] = arr[a + 1];
}
n = n - 1;
}
void insertElement(int a,int b){
addLastElement(arr[n-1]);
int k = n;
int l = b;
printf("%d", k);
for (; a < k; k--) {
arr[k-1] = arr[k-2];
}
arr[a] = l;
}
void minEl0() {
int m = findMin();
int r;
int k = n;
for (int i = 0; i < n; i++) {
if (arr[i] == m) {
r = i;
}
}
addLastElement(arr[n - 1]);
printf("%d", k);
while (k > 0) {
arr[k] = arr[k - 1];
k--;
}
arr[r] = 0;
}
void priz() {
int m = findMax();
addLastElement(arr[n - 1]);
int r;
int k = n;
for (; m+2 < k; k--) {
arr[k] = arr[k - 1];
k--;
}
arr[m + 1] = 0;
}
void main() {
/*char s[10] = "Hi!";
printf("len = %d\n", strlen_my(s));
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
int item;
do {
printf("\n");
printf("------------------------------\n");
printf("Ńîäĺđćčěîĺ ěŕńńčâŕ:");
printElements();
printf("Âűáĺđčňĺ íóćíóţ âŕě îďĺđŕöčţ:\n");
printf("1: Ââĺńňč ń ęëŕâčŕňóđű ěŕńńčâ\n");
printf("2: Óäŕëčňü âűáđŕííűé ýëĺěĺíň\n");
printf("3: Ââĺńňč ýëĺěĺíň íŕ âűáđŕííîĺ ěĺńňî\n");
printf("4: Óäŕëčňü ěčíčěŕëüíűé ýëĺěĺíň\n");
printf("5: Ďĺđĺä ěčíčěŕëüíűě ýëĺěĺíňîě âńňŕâčňü 0\n");
printf("6: Ďîńëĺ ěŕęńčěŕëüíîăî ÷¸ňíîăî ýëĺěĺíňŕ âńňŕâčňü 0\n");
s[3] = ' '; s[4] = '\0';
printf("len = %d\n", strlen_my(s));
s[4] = 'W'; s[5] = 'o'; s[6] = 'r'; s[7] = 'l';
s[8] = 'd'; s[9] = '\0';
printf("len = %d\n", strlen_my(s));
*/
char dest[10] = "YYYYY";
char src[10] = "GGGGG";
strcpy_my(dest, src);
printf("\n");
printf("0: Âűéňč čç ďđîăđŕěěű \n");
printf("Âűáđŕííŕ˙ îďĺđŕöč˙ >>>>>> ");
scanf_s("%d", &item);
switch (item) {
case 1:
keyboardInput();
break;
case 2:
printf("Ââĺäčňĺ číäĺęń óäîë˙ĺěîăî ýëĺěĺíňŕ ");
int a;
scanf_s("%d", &a);
deleteElement(a);
break;
case 3:
{
printf("Ďđĺä ęŕęčě ýëĺěĺíňîě âńňŕâčňü íîâűé? Číäĺęń = ");
int a;
scanf_s("%d", &a);
printf("Ęŕęîĺ çíŕ÷ĺíčĺ âńňŕâčňü = ");
int b;
scanf_s("%d", &b);
insertElement(a,b);
break;
break;
}
case 4:
{
deleteElement(findMin2());
break;
}
case 5:
{
minEl0();
break;
}
case 6:
{
priz();
break;
}
}
} while (item != 0);
}