Lab.OIT/Lab09.10.OAIP.ProkonovKirill/Source.cpp

283 lines
4.1 KiB
C++
Raw Normal View History

2024-10-31 12:20:44 +04:00
#include <stdio.h>
//void main() {
// printf("main() start\n" "main() finish\n");
//
// //printf("main() finish\n");
//}
//89................
2024-10-31 12:20:44 +04:00
//int isPrime(int num) {
// int del = 2;
// while (del < num) {
// // <20><><EFBFBD><EFBFBD> num <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> del
// if (num % del == 0) {
// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0, <20>.<2E>. <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// return 0;
// }
// del++;
// }
// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1, <20>.<2E>. <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><> 2 <20><> num-1
// // <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// return 1;
//}
// labsa
//
////void main() {
//// int n = 10000;
////
//// int a = 1;
//// int i = 0;
//// while (i < n) {
//// if (isPrime(a)) {
//// printf("%d ", a);
//// i++;
//// }
//// a++;
//// }
////}
//
//void main() {
// int num = 20;
//
// while (1) {
// if (isPrime(num)) {
// printf("%d ", num);
// break;
// }
// num++;
// }
//
//}
#include <stdio.h>
#include <Windows.h>
void print1_10() {
int a = 1;
do {
printf("%d ", a);
a += 1;
} while (a <= 10);
}
void print10_1() {
int a = 10;
do {
printf("%d ", a);
a -= 1;
} while (a >= 1);
}
void print50dds() {
int a = 1;
int i = 1;
do {
printf("%d ", a);
a += 2;
i += 1;
} while (i <= 5);
}
void print_100to10_step10() {
int a = 100;
//int i = 100;
while(a >= 10) {
printf("%d ", a);
a -= 10;
}
}
void print_1000_to100_step100() {
int a = 1000;
while (a >= 100) {
printf("%d ", a);
a -= 100;
}
}
void print_checkout() {
float s;
float procent;
int years;
printf("S = ");
scanf_s("%f", &s);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> = ");
scanf_s("%f", &procent);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> = ");
scanf_s("%d", &years);
int i = 1;
float current_amount = s;
while (i <= years) {
current_amount *= (1 + procent / 100);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> %d <20><><EFBFBD>: %.2f\n", i, current_amount);
++i;
}
}
void print_1000_to0_step23() {
int a = 1000;
label_while:
if (a>=0) {
printf("%d ", a);
a -= 23;
goto label_while;
}
}
void print_factorial() {
int a = 1;
int n;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (N): ");
scanf_s("%d", &n);
int factorial1 = 1;
while (a <= n) {
factorial1 *= a;
printf("%d ", factorial1);
a++;
}
}
void print_Fibonachi(){
printf("N <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n");
int f;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> N: ");
scanf_s("%d", &f);
int a1 = 1, b1 = 1, c1;
if (f == 1) {
printf("0 ");
}
else if (f == 2) {
printf("0 1 ");
}
else {
printf("0 1 1 ");
int count = 3;
while (count < f) {
c1 = a1 + b1;
printf("%d ", c1);
a1 = b1;
b1 = c1;
count++;
};
}
printf("\n");
}
void prime_factors() {
int n;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> n: ");
scanf_s("%d", &n);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> %d <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: ", n);
int del = 2;
label_while:
if (n > 1) {
if (n % del == 0) {
printf("%d ", del);
n = n/del;
}
else {
del++;
}
goto label_while;
}
printf("\n");
}
void main() {
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
int n;
do {
printf("\n");
printf("\n");
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n");
printf("1: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><> 1 <20><> 10\n");
printf("2: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><> 10 <20><> 1\n");
printf("3: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 5 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> 1\n");
printf("\n");
printf("0: <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
printf("11: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><> 100 <20><> 10 <20> <20><><EFBFBD><EFBFBD><EFBFBD> 10\n");
printf("12: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><> 1000 <20><> 100 <20> <20><><EFBFBD><EFBFBD><EFBFBD> 100\n");
printf("13: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
printf("\n");
printf("20: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><> 1000 <20><> 0 <20> <20><><EFBFBD><EFBFBD><EFBFBD> 23\n");
printf("21: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
printf("22: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> N <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
printf("23: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
scanf_s("%d", &n);
switch (n) {
case 1:
printf("\n");
print1_10();
break;
case 2:
printf("\n");
print10_1();
break;
case 3:
printf("\n");
print50dds();
break;
case 11:
printf("\n");
print_100to10_step10();
break;
case 12:
printf("\n");
print_1000_to100_step100();
break;
case 13:
printf("\n");
print_checkout();
break;
case 20:
printf("\n");
print_1000_to0_step23();
break;
case 21:
printf("\n");
print_factorial();
break;
case 22:
printf("\n");
print_Fibonachi();
break;
case 23:
printf("\n");
prime_factors();
break;
}
} while (n != 0);
}