Compare commits

..

No commits in common. "fbdb3d8b9494d3a9c2c99910d004e299fc0be288" and "c8c34433ca2c1b3ccf4fcf74b858c0d89e204101" have entirely different histories.

193
Lab
View File

@ -1,176 +1,37 @@
#include <stdio.h> #include <stdio.h>
#include <Windows.h> #include <Windows.h>
#define NUM_ELEMENTS 100 int strlen_my(char *s)
{
int arr[NUM_ELEMENTS]; int i = 0;
int n = 0; char* p = s;
void addLastElement(int a) { while (*p++) {
arr[n++] = a; i++;
}
return i;
} }
void printElements() { int strcpy_my(char* dest, char* src)
for (int i = 0; i < n; i++) { {
printf("%d ", arr[i]); int i = 0;
} while (src[i] != "\0") {
printf("\n"); dest[i] = src[i];
i++;
}
printf("\nBû ïîëó÷àåòå ñòðîêó s = \"%s\"", dest);
} }
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() { void main() {
SetConsoleCP(1251); /*char s[10] = "Hi!";
SetConsoleOutputCP(1251); printf("len = %d\n", strlen_my(s));
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));
printf("\n"); s[4] = 'W'; s[5] = 'o'; s[6] = 'r'; s[7] = 'l';
printf("0: Âűéňč čç ďđîăđŕěěű \n"); s[8] = 'd'; s[9] = '\0';
printf("Âűáđŕííŕ˙ îďĺđŕöč˙ >>>>>> "); printf("len = %d\n", strlen_my(s));
*/
scanf_s("%d", &item); char dest[10] = "YYYYY";
switch (item) { char src[10] = "GGGGG";
case 1: strcpy_my(dest, src);
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);
} }