From fae8efe512d7d16bacedc290cf1c13411f38f4b2 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 22 Mar 2024 16:47:24 +0300 Subject: [PATCH] =?UTF-8?q?:=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=87=D0=B0=D1=81=D1=82=D1=8C=20?= =?UTF-8?q?=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2=20=D0=B2=D1=8B=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D0=BD=D0=B5=D0=BD=D0=BD=D1=8B=D1=85=20=D0=B7=D0=B0=D0=B4?= =?UTF-8?q?=D0=B0=D1=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Добавлены задачи, выполненные по мануалу си. Пополнение задач по мере их выполнения и добавления комментариев. [Новые программы] --- 1.10.txt | 20 ++++++++++++++ 1.11.txt | 26 ++++++++++++++++++ 1.12.txt | 27 +++++++++++++++++++ 1.13.txt | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1.15.txt | 17 ++++++++++++ 1.4.c | 18 +++++++++++++ 1.5.txt | 8 ++++++ 1.6-1.7.txt | 11 ++++++++ 1.8.txt | 21 +++++++++++++++ 1.9.txt | 24 +++++++++++++++++ 2.1.txt | 30 +++++++++++++++++++++ 2.2.txt | 23 ++++++++++++++++ 3.3.txt | 40 ++++++++++++++++++++++++++++ 13 files changed, 341 insertions(+) create mode 100644 1.10.txt create mode 100644 1.11.txt create mode 100644 1.12.txt create mode 100644 1.13.txt create mode 100644 1.15.txt create mode 100644 1.4.c create mode 100644 1.5.txt create mode 100644 1.6-1.7.txt create mode 100644 1.8.txt create mode 100644 1.9.txt create mode 100644 2.1.txt create mode 100644 2.2.txt create mode 100644 3.3.txt diff --git a/1.10.txt b/1.10.txt new file mode 100644 index 0000000..d7927aa --- /dev/null +++ b/1.10.txt @@ -0,0 +1,20 @@ +#include + /* Бэкспейс не видит. нужно подключать conio.h */ +int main() +{ + int c; + + for(;(c=getchar())!= EOF;) + { + if(c=='\t') + printf("\\t"); + else if(c=='\b') + printf("\\b"); + else if(c=='\\') + printf("\\s"); + else + printf("%c",c); + } + + getch(); +} \ No newline at end of file diff --git a/1.11.txt b/1.11.txt new file mode 100644 index 0000000..a9b02aa --- /dev/null +++ b/1.11.txt @@ -0,0 +1,26 @@ +#include +/*Ошибка при переносе слова на новую строку*/ +#define IN 1 /* внутри слова */ +#define OUT 0 /* вне слова */ + +int main() +{ + int c, nl, nw, nc, state; + state = OUT; + nl = nw = nc = 0; + + while ((c = getchar()) != EOF) { + ++nc; + if (c == '\n') + ++nl; + if (c == ' ' || c == '\n' || c == '\t') + state = OUT; + else if (state == OUT) { + state = IN; + ++nw; + } + } + printf("%d %d %d\n", nl, nw, nc); + + return 0; +} \ No newline at end of file diff --git a/1.12.txt b/1.12.txt new file mode 100644 index 0000000..1dc74bf --- /dev/null +++ b/1.12.txt @@ -0,0 +1,27 @@ +#include + +#define IN 1 /* внутри слова */ +#define OUT 0 /* вне слова */ + +int main() +{ + int c, nl, nw, nc, state; + state = OUT; + nl = nw = nc = 0; + + while ((c = getchar()) != EOF) { + if (c == ' ' || c == '\n' || c == '\t'){ + state = OUT; + printf("%c \n",c); + } + else if (state == OUT) { + state = IN; + printf("%c",c); + } + else { + printf("%c",c); + } + } + + return 0; +} \ No newline at end of file diff --git a/1.13.txt b/1.13.txt new file mode 100644 index 0000000..043a386 --- /dev/null +++ b/1.13.txt @@ -0,0 +1,76 @@ +#include +/* подсчет цифр, символов-разделителей и прочих символов */ +int main() +{ + int c, i, j, nwhite, nother; + int ndigit[10]; + nwhite = nother = 0; + for (i = 0; i < 10; ++i) + ndigit[i] = 0; + while ((c = getchar()) != EOF) + { + if (c >= '0' && c <= '9') + ++ndigit[c - '0']; + else if (c == ' ' || c == '\n' || c == '\t') + ++nwhite; + else + ++nother; + } + printf("цифры ="); + for (i = 0; i < 10; ++i) + printf(" %d", ndigit[i]); + printf(", символы-разделители = %d, прочие = %d\n", nwhite, nother); + + for(i = 0; i<100; ++i){ + for(j = 0; j<10; ++j){ + --ndigit[j]; + if (ndigit[j] >= 0) + printf("|"); + else if (ndigit[j] == -1) + printf("-"); + else + printf(" "); + } + printf("\n"); + } + return 0; +} +#include +#include + +#define MAXLEN 30 + +void resh(char s1[], char s2[]); + +int main() +{ +char in[MAXLEN] = "-A-Z1-9\0"; +char out[MAXLEN]; + + printf("s1 = %s\n",in); + resh(in, out); + printf("s2 = %s\n",out); + return 0; +} + +void resh(char s1[], char s2[]) +{ +int i, j; + for( i = 0, j = 0; s1[i] != 0; i++){ + if (s1[i] = '-'){ + if (isdigit(s1[i-1])&&isdigit(s1[i+1])&&s1[i-1] < s1[i+1]|| + islower(s1[i-1])&&islower(s1[i+1])&&s1[i-1] < s1[i+1]|| + isupper(s1[i-1])&&isupper(s1[i+1])&&s1[i-1] < s1[i+1]){ + for(char t = (char)(s1[i-1]+1); t + +float temp(int fahr); + +/* печать таблицы температур по Фаренгейту и Цельсию */ +int main() +{ + int fahr; + for (fahr = 300; fahr >= 0; fahr = fahr - 20) + printf("%3d %6.1f\n", fahr, temp(fahr)); + return 0; +} + +float temp(int fahr) +{ + return (5.0 / 9.0) * (fahr - 32); +} \ No newline at end of file diff --git a/1.4.c b/1.4.c new file mode 100644 index 0000000..0d71326 --- /dev/null +++ b/1.4.c @@ -0,0 +1,18 @@ +#include +/* печать таблицы температур по Фаренгейту и Цельсию для +celsius = 0, 20 ... 300; вариант с плавающей точкой */ +int main() +{ + float fahr, celsius; + int lower, upper, step; + lower = 0; /* нижняя граница таблицы температур */ + upper = 300; /* верхняя граница */ + step = 10; /* шаг */ + celsius = lower; + printf ("Таблица перевода цельс. в фар.\n"); + while (celsius <= upper) { + fahr = (9.0/5.0) * celsius + 32.0; + printf ("%3.0f %6.2f\n", celsius, fahr); + celsius = celsius + step; + } +} \ No newline at end of file diff --git a/1.5.txt b/1.5.txt new file mode 100644 index 0000000..279c84f --- /dev/null +++ b/1.5.txt @@ -0,0 +1,8 @@ +#include +/* печать таблицы температур по Фаренгейту и Цельсию */ +int main() +{ + int fahr; + for (fahr = 300; fahr >= 0; fahr = fahr - 20) + printf ("%3d %6.1f\n", fahr, (5.0/9.0)*(fahr-32)); +} \ No newline at end of file diff --git a/1.6-1.7.txt b/1.6-1.7.txt new file mode 100644 index 0000000..3e0d8da --- /dev/null +++ b/1.6-1.7.txt @@ -0,0 +1,11 @@ +#include + +int main() +{ + int c; + while ((c = getchar()) != EOF) { + printf("Значение EOF\n",EOF); + putchar(c); + } + return 0; +} \ No newline at end of file diff --git a/1.8.txt b/1.8.txt new file mode 100644 index 0000000..4eb42a1 --- /dev/null +++ b/1.8.txt @@ -0,0 +1,21 @@ +#include + +int main() +{ + int c; + int tabulate, ws, new; + tabulate = ws = new = 0; + for(;(c=getchar())!= EOF;) + { + if(c=='\t') + ++tabulate; + else if(c==' ') + ++ws; + else if(c=='\n') + ++new; + /*else + printf("%c",c);*/ + } + printf("Пробелов = %d Табуляций = %d Новых строк = %d", ws, tabulate, new); + getch(); +} \ No newline at end of file diff --git a/1.9.txt b/1.9.txt new file mode 100644 index 0000000..ce5599e --- /dev/null +++ b/1.9.txt @@ -0,0 +1,24 @@ +#include + +int main() +{ + int c; + int ws = 0; + + while ((c = getchar()) != EOF) + { + if (c == ' ') + { + ++ws; + if (ws < 2) + printf("%c", c); + } + else + { + printf("%c", c); + ws = 0; + } + } + + return 0; +} \ No newline at end of file diff --git a/2.1.txt b/2.1.txt new file mode 100644 index 0000000..b3e5199 --- /dev/null +++ b/2.1.txt @@ -0,0 +1,30 @@ +#include +#include + + int main() + { + printf("%d <= char <= %d\n", CHAR_MIN, CHAR_MAX); + printf("%d <= int <= %d\n", INT_MIN, INT_MAX); + printf("%ld <= long <= %ld\n", LONG_MIN, LONG_MAX); + printf("%d <= signed char <= %d\n", SCHAR_MIN, SCHAR_MAX); + printf("%d <= short <= %d\n", SHRT_MIN, SHRT_MAX); + printf("0 <= unsigned char <= %d\n", UCHAR_MAX); + printf("0 <= unsigned int <= %u\n", UINT_MAX); + printf("0 <= unsigned long <= %lu\n", ULONG_MAX); + printf("0 <= unsigned short <= %d\n", USHRT_MAX); + return 0; + } + +int main() +{ + unsigned char x; + + for (x = 1; x > x-1; ++x) { + if (x < 0) + break; + printf("%d\n", x); // печатаем для отладки программы + } + printf("MIN: %d\n", x); + printf("MAX: %d\n", --x); + return 0; +} \ No newline at end of file diff --git a/2.2.txt b/2.2.txt new file mode 100644 index 0000000..a8d731a --- /dev/null +++ b/2.2.txt @@ -0,0 +1,23 @@ +#include +int lim = 10; +int main() +{ + int i, c; + char s[lim]; + i = 0; + while (i < lim-1){ + c = getchar(); + if (с == EOF) + break; + else if (с == '\n') + break; + else + s[i] = c; + + ++i; + } + s[i] = '\0'; + +//for (i = 0; i < lim-1 && (с = getchar()) != EOF && с != '\n'; ++i) + //s[i] = c; +} \ No newline at end of file diff --git a/3.3.txt b/3.3.txt new file mode 100644 index 0000000..564eb79 --- /dev/null +++ b/3.3.txt @@ -0,0 +1,40 @@ +#include +#include + +#define MAXLEN 30 + +void expand(char s1[], char s2[]); + +int main() +{ + char in[MAXLEN] = "-A-Z1-9\0"; + char out[MAXLEN]; + + printf("s1 = %s\n", in); + expand(in, out); + printf("s2 = %s\n", out); + + return 0; +} +void expand(char s1[], char s2[]) +{ + int i, j; + char t; + + for (i = 0, j = 0; s1[i] != '\0'; i++) + { + if ( s1[i] == '-' ) + { + if ( (isdigit(s1[i-1]) && isdigit(s1[i+1]) && (s1[i-1]