This commit is contained in:
Павел Родионов
2025-11-13 18:21:23 +07:00
parent e266a25b45
commit 2fca7b75f5
28 changed files with 74 additions and 4 deletions
+14
View File
@@ -0,0 +1,14 @@
#include <stdio.h>
double min(double x, double y);
int main(){
double x,y;
printf("Enter: num1 num2\nEnter: ");
scanf("%lf %lf",&x,&y);
printf("lower: %lf\n",min(x,y));
return 0;
}
double min(double x, double y){
return ((x>y)?x:y);
}
BIN
View File
Binary file not shown.
+28
View File
@@ -0,0 +1,28 @@
#include <stdio.h>
void to_base_n(unsigned long *n, int *b);
int main(void){
unsigned long num;
int bin;
printf("Enter: num base(2-10)\t(q to quit):\n");
printf("Enter: ");
while (scanf(" %ld %d", &num, &bin) == 2){
if(bin>1&&bin<11){
to_base_n(&num,&bin);
putchar('\n');
printf("Enter: ");
}else(printf("base is out of range\nEnter: "));
}
return 0;
}
void to_base_n(unsigned long *n, int *b){
int r;
r = *n % *b;
if (*n >= *b){
*n = *n / *b;
to_base_n(n,b);
}
putchar('0' + (r % *b));
return;
}
+23
View File
@@ -0,0 +1,23 @@
#include <stdio.h>
int fibonacci(int n);
int main() {
int n;
printf("Enter: num\nEnter: ");
scanf("%d",&n);
printf("fibonacci(%d) = %d",n,fibonacci(n));
return 0;
}
int fibonacci(int n){
if(n<=0) return 0;
if(n==1) return 1;
int a = 0, b = 1, next;
for(int i = 2;i <= n;i++){
next = a + b;
a = b;
b = next;
}
return b;
}
+9
View File
@@ -0,0 +1,9 @@
#include <stdio.h>
int main() {
int i = 0;
while(getchar() != EOF)
i++;
printf("%d",i);
return 0;
}
+39
View File
@@ -0,0 +1,39 @@
#include <stdio.h>
int main(){
int ch,c,m[10];
ch = c = 0;
printf("ascii symb - its num\n");
while((ch = getchar()) != EOF){
m[c] = ch;
c++;
if(c == 10){
for(c = 0; c < 10; c++){
switch(m[c]){
case '\n':
printf(" \\n - %3d ",m[c]);
break;
case '\t':
printf(" \\t - %3d ",m[c]);
break;
case ' ':
printf("\"%c\" - %3d ",m[c],m[c]);
break;
default:
if(m[c]<' '){
printf(" ^%c - %3d ", m[c] + 64, m[c]);
}else
if(m[c] == 127){
printf(" ^? %3d ",m[c]);
}else printf("%3c - %3d ",m[c],m[c]);
}
}
printf("\n");
c = 0;
}
}
return 0;
}
+37
View File
@@ -0,0 +1,37 @@
#include <stdio.h>
#include <wchar.h>
#include <locale.h>
int alpha(wchar_t x);
int main() {
setlocale(LC_ALL, "");
int smol = 0,big = 0,symb = 0;
wchar_t x;
while((x = getwchar()) != WEOF){
switch(alpha(x)){
case 1: smol++;break;
case 2: big++;break;
default: symb++;break;
}
}
printf("Пропись: %d\tСтрочных: %d\tОстальное: %d",smol,big,symb);
return 0;
}
int alpha(wchar_t x){
if (x >= L'A' && x <= L'Z')
return 2;
else if (x >= L'a' && x <= L'z')
return 1;
else if (x >= L'А' && x <= L'Я')
return 2;
else if (x >= L'а' && x <= L'я')
return 1;
else if (x == L'Ё')
return 2;
else if (x == L'ё')
return 1;
else
return -1;
}
+22
View File
@@ -0,0 +1,22 @@
#include <stdio.h>
#include <wchar.h>
#include <locale.h>
int main() {
setlocale(LC_ALL, "");
float ch = 0,words = 0,o = 0;
wchar_t x;
while((x = getwchar()) != WEOF){
switch(x){
case ' ':
ch += o;
if(o>0) words++;
o = 0;
break;
default:
o++;
}
}
printf("\nch per word - %.2f\n",ch/words);
return 0;
}
+40
View File
@@ -0,0 +1,40 @@
#include <stdio.h>
int main(void){
int guess = 1,ext = 1;
int x = 50, max = 100, min = 0;
printf("Загадайте число 0 - 100, я буду его отгадывать\n");
printf("Вы должны сказать, это число меньше, больше или это оно\n");
printf("За ответ принимается только l(Меньше) b(Больше) y(Оно)\n");
while(ext != 0){
printf("Это число %d?\n",x);
ext = getchar();
while(getchar()!='\n')
continue;
switch(ext){
case 'l':
max = x - 1;
x = (max+min)/2;
guess++;
break;
case 'b':
min = x + 1;
x = (max+min)/2;
guess++;
break;
case 'y':ext = 0;break;
}
if(x<0||x>100){
printf("Вы загадали число за пределами ожиданий!\n");
ext=0;
break;
}
}
if(x>=0&&x<=100)
printf("Загаданное число - %d\t Число угадываний - %d",x,guess);
return 0;
}
+11
View File
@@ -0,0 +1,11 @@
#include <stdio.h>
int main(void){
int ch;
while((ch = getchar()) == ' ')
continue;
while (getchar() != '\n')
continue;
printf("%c",ch);
return 0;
}
BIN
View File
Binary file not shown.
+61
View File
@@ -0,0 +1,61 @@
#include <stdio.h>
#define t1 8.75
#define t2 9.33
#define t3 10.00
#define t4 11.20
// #define t 10 //zp
#define s 40 //sverh
#define u 1.5 //sverh*
#define n1 0.15 //tax1
#define n2 0.2
#define n3 0.25
#define m1 300 //maxbeftax2
#define m2 150
int main() {
int h,sw,x,swt,exit,scan;
float t,tax,a;
exit = x = swt = scan = 1;
while(exit){
printf("hours: ");
while(scanf("%d", &h)!=1){
printf("input err\n");
if(getchar() == EOF) return 0;
while (getchar() != '\n') continue;
printf("hours: ");
}
while (getchar() != '\n') continue;
do{
while (getchar() != '\n') continue;
printf("Choose tarif:\n");
printf("a) $%.2f/h\tb) $%.2f/h\n",t1,t2);
printf("c) $%.2f/h\td) $%.2f/h\n",t3,t4);
printf("q) exit\nInput: ");
sw = getchar();
if(getchar() == EOF){return 0;}
while (getchar() != '\n') continue;
switch(sw){
case 'a': t = t1; swt = 0; break;
case 'b': t = t2; swt = 0; break;
case 'c': t = t3; swt = 0; break;
case 'd': t = t4; swt = 0; break;
case 'q': exit = 0; break;
default: printf("input err\n");
}
}while(swt&&exit);
if(!swt && exit){
if (h>s){tax = a = (s*t + ((h-s) * (t*u)));}
else(tax = a = h*t);
if (tax>m1)
{
if(tax>m2){tax = (m1*n1) + (m2*n2) + ((tax-m1-m2)*n3);}
else(tax = (m1*n1) + ((tax-m1)*n2));
}
else (tax*=n1);
printf("Acc: %.3f\nTax: %.3f\nReceived: %.3f\n",a,tax,a-tax);
}}
return 0;
}
+61
View File
@@ -0,0 +1,61 @@
#include <stdio.h>
#define t1 8.75
#define t2 9.33
#define t3 10.00
#define t4 11.20
// #define t 10 //zp
#define s 40 //sverh
#define u 1.5 //sverh*
#define n1 0.15 //tax1
#define n2 0.2
#define n3 0.25
#define m1 300 //maxbeftax2
#define m2 150
int main() {
int h,sw,x,swt,exit,scan;
float t,tax,a;
exit = x = swt = scan = 1;
while(exit){
printf("hours: ");
while(scanf("%d", &h)!=1){
printf("input err\n");
if(getchar() == EOF) return 0;
while (getchar() != '\n') continue;
printf("hours: ");
}
while (getchar() != '\n') continue;
do{
while (getchar() != '\n') continue;
printf("Choose tarif:\n");
printf("a) $%.2f/h\tb) $%.2f/h\n",t1,t2);
printf("c) $%.2f/h\td) $%.2f/h\n",t3,t4);
printf("q) exit\nInput: ");
sw = getchar();
if(getchar() == EOF){return 0;}
while (getchar() != '\n') continue;
switch(sw){
case 'a': t = t1; swt = 0; break;
case 'b': t = t2; swt = 0; break;
case 'c': t = t3; swt = 0; break;
case 'd': t = t4; swt = 0; break;
case 'q': exit = 0; break;
default: printf("input err\n");
}
}while(swt&&exit);
if(!swt && exit){
if (h>s){tax = a = (s*t + ((h-s) * (t*u)));}
else(tax = a = h*t);
if (tax>m1)
{
if(tax>m2){tax = (m1*n1) + (m2*n2) + ((tax-m1-m2)*n3);}
else(tax = (m1*n1) + ((tax-m1)*n2));
}
else (tax*=n1);
printf("Acc: %.3f\nTax: %.3f\nReceived: %.3f\n",a,tax,a-tax);
}}
return 0;
}
+63
View File
@@ -0,0 +1,63 @@
#include <stdio.h>
void calc(int func);
int main() {
int exit = 1,sw;
do{
printf("\nВыберите операцию:\n");
printf("a) сложение\tb) вычитание\n");
printf("c) умножение\td) деление\n");
printf("q) exit\nInput: ");
sw = getchar();
switch(sw){
case 'a': calc(1); break;
case 'b': calc(2); break;
case 'c': calc(3); break;
case 'd': calc(4); break;
case 'q': exit = 0; break;
}}while(exit);
return 0;
}
void calc(int func){
float n1,n2;
int x;
printf("Введите первое число: ");
while(scanf(" %f",&n1)!=1){
printf("То что вы ввели не является числом.\n");
printf("Введите первое число: ");
while(getchar()!='\n') continue;
}
printf("Введите второе число: ");
do{
x = (scanf(" %f",&n2) != 1);
if(x){
printf("То что вы ввели не является числом.\n");
printf("Введите второе число: ");
}else
if(n2 == 0&&func==4){
printf("Введите число отличное от 0\n");
printf("Введите второе число: ");
x = 1;
}
while(getchar()!='\n') continue;
}while(x);
switch(func){
case 1:
printf("%f + %f = %f\n",n1,n2,n1+n2);
break;
case 2:
printf("%f - %f = %f\n",n1,n2,n1-n2);
break;
case 3:
printf("%f * %f = %f\n",n1,n2,n1*n2);
break;
case 4:
printf("%f / %f = %f\n",n1,n2,n1/n2);
break;
}
}
+20
View File
@@ -0,0 +1,20 @@
#include <stdio.h>
void min(char ch, char i, char j);
int main(){
char ch, i, j;
printf("Enter: char i j\nEnter: ");
scanf(" %c %c %c",&ch,&i,&j);
min(ch,i,j);
return 0;
}
void min(char ch, char i, char j){
int c = i;
for(;i<=j;i++){printf("%c\t",i);}
printf("\n");
i = c;
for(;i<=j;i++){printf("%c\t",ch);}
printf("\n");
}
+21
View File
@@ -0,0 +1,21 @@
#include <stdio.h>
void table(char ch, int a, int b);
int main(){
char ch;
int a,b;
printf("Enter: Char num1 num2\nEnter: ");
scanf(" %c %d %d",&ch,&a,&b);
table(ch,a,b);
return 0;
}
void table(char ch, int a, int b){
//for(int i = 0;i<=a;i++){printf("%d",i);}
printf("\n");
for(int i = 1;i<=b;i++){
//printf("%d",i);
for(int x = 1;x<=a;x++){printf("%c",ch);}
printf("\n");
}
}
+18
View File
@@ -0,0 +1,18 @@
#include <stdio.h>
double garmony(double a,double b);
int main(){
double a, b;
printf("Enter: num1 num2\nEnter: ");
scanf(" %lf %lf",&a,&b);
printf("garmony = %lf",garmony(a,b));
return 0;
}
double garmony(double a, double b){
double x;
a *= -1;
b *= -1;
x = (((a+b)/2)*-1);
return x;
}
+17
View File
@@ -0,0 +1,17 @@
#include <stdio.h>
double larger_of(double a, double b);
int main() {
double a,b,c;
printf("Print: num1 num2\nPrint: ");
scanf(" %lf %lf",&a,&b);
c = larger_of(a,b);
a = c;
b = c;
printf("Larger value is: %lf",a);
return 0;
}
double larger_of(double a, double b){
return ((a>b)?a:b);
}
+30
View File
@@ -0,0 +1,30 @@
#include <stdio.h>
void scale(double *a, double *b, double *c);
int main() {
double a,b,c;
printf("Print: num1 num2 num3\nPrint: ");
scanf(" %lf %lf %lf",&a,&b,&c);
scale(&a,&b,&c);
printf("%lf > %lf > %lf",a,b,c);
return 0;
}
void scale(double *a, double *b, double *c){
double result[3];
result[0] = *a;
result[1] = *b;
result[2] = *c;
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 2 - i; ++j) {
if (result[j] < result[j + 1]) {
double tmp = result[j];
result[j] = result[j + 1];
result[j + 1] = tmp;
}
}
}
*a = result[0];
*b = result[1];
*c = result[2];
}
+32
View File
@@ -0,0 +1,32 @@
#include <stdio.h>
#include <wchar.h>
#include <wctype.h>
#include <locale.h>
int alpha(wchar_t x);
int main() {
setlocale(LC_ALL, "");
wchar_t x;
while((x = getwchar()) != WEOF){
if(iswalpha(x)){
wprintf(L"%lc - %d\n",x,alpha(x));
}
}
return 0;
}
int alpha(wchar_t x){
if (x >= L'A' && x <= L'Z')
return x - L'A' + 1;
else if (x >= L'a' && x <= L'z')
return x - L'a' + 1;
else if (x >= L'А' && x <= L'Я')
return x - L'А' + 1;
else if (x >= L'а' && x <= L'я')
return x - L'а' + 1;
else if (x == L'Ё' || x == L'ё')
return 7;
else
return -1;
}
+46
View File
@@ -0,0 +1,46 @@
#include <stdio.h>
double power(double n, int р);
int main(void){
double x, xpow;
int exp;
printf("Write: num pow\t(q for exit)\nWrite: ") ;
while (scanf(" %lf %d", &x, &exp) == 2){
xpow = power(x,exp);
if (xpow != 0){
printf ("%.2lf в степени %d равно %lf\n", x, exp, xpow);}
printf("Write: ");
}
return 0;
}
double power (double n, int p){
if ((p == 0)&&(n == 0)){
printf("Result of 0 in pow 0 is undefind\n");
return 0;
}
if ((p == 0)||(n == 0)){
return 1;
}
if (p>0){
double pow = 1;
int i;
for (i =1; i <= p; i++)
pow *= n;
return pow;
}
if (p<0){
double pow = 1;
int i;
for (i =1; i <= -p; i++)
pow *= n;
pow = (1 / pow);
return pow;
}
}
BIN
View File
Binary file not shown.
+36
View File
@@ -0,0 +1,36 @@
#include <stdio.h>
void power(double *x, int *exp, double *xpow, int *i);
int main(){
double x, xpow;
int exp, i;
i = 1;
printf("Write: num pow\t(q for exit)\nWrite: ") ;
while (scanf(" %lf %d", &x, &exp) == 2){
if ((x == 0) && (exp == 0)){
printf("Result of 0 in pow 0 is undefind\n");
}
else if(exp == 0){xpow = 1;}
else({
xpow = x;
power(&x,&exp,&xpow,&i);
});
if ((x != 0)||(exp != 0)){
printf ("%.2lf в степени %d равно %lf\n", x, exp, xpow);}
printf("Write: ");
}
return 0;
}
void power (double *x, int *exp, double *xpow, int *i){
if(*i<*exp){
*xpow = (*xpow * *x);
(*i)++;
power(x, exp, xpow, i);
}else({
if (*exp<0) *xpow = (1 / *xpow);
(*i) = 1;
});
}
+6
View File
@@ -0,0 +1,6 @@
adaGz7908
3123
4
234
.././././??'"\\\||"'xXФЫВчя312еЁ
BIN
View File
Binary file not shown.