Lab.OIT/Lab09.10.OAIP.ProkonovKirill/Source.cpp
2024-10-31 12:24:10 +04:00

283 lines
4.1 KiB
C++

#include <stdio.h>
//void main() {
// printf("main() start\n" "main() finish\n");
//
// //printf("main() finish\n");
//}
//89...
//int isPrime(int num) {
// int del = 2;
// while (del < num) {
// // åñëè num íàöåëî äåëèòüñÿ íà del
// if (num % del == 0) {
// // âîçâðàùàåì 0, ò.ê. ÷èñëî íå ïðîñòîå
// return 0;
// }
// del++;
// }
// // âîçâðàùàåì 1, ò.ê. íè îäíî ÷èñëî îò 2 äî num-1
// // íå ÿâëÿåòñÿ äåëèòåëåì
// 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("Ïðîöåíò = ");
scanf_s("%f", &procent);
printf("Êîëè÷åñòâî ëåò = ");
scanf_s("%d", &years);
int i = 1;
float current_amount = s;
while (i <= years) {
current_amount *= (1 + procent / 100);
printf("×åðåç %d ëåò: %.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("Ââåäèòå êîëè÷åñòâî ôàêòîðèàëîâ (N): ");
scanf_s("%d", &n);
int factorial1 = 1;
while (a <= n) {
factorial1 *= a;
printf("%d ", factorial1);
a++;
}
}
void print_Fibonachi(){
printf("N ÷èñåë Ôèáîíà÷÷è:\n");
int f;
printf("Ââåäèòå 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("Ââåäèòå ÷èñëî n: ");
scanf_s("%d", &n);
printf("Ðàçëîæåíèå ÷èñëà %d íà ïðîñòûå ìíîæèòåëè: ", 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("Âûáåðèòå íóæíóþ âàì îïåðàöèþ:\n");
printf("1: Âûâåñòè ÷èñëà îò 1 äî 10\n");
printf("2: Âûâåñòè ÷èñëà îò 10 äî 1\n");
printf("3: Âûâåñòè 5 ïåðâûõ íå÷åòíûõ ÷èñåë íà÷èíàÿ ñ 1\n");
printf("\n");
printf("0: Âûéòè èç ïðîãðàììû\n");
printf("11: Âûâåñòè ÷èñëà îò 100 äî 10 ñ øàãîì 10\n");
printf("12: Âûâåñòè ÷èñëà îò 1000 äî 100 ñ øàãîì 100\n");
printf("13: Âûâåñòè îñòàòîê\n");
printf("\n");
printf("20: Âûâåñòè ÷èñëà îò 1000 äî 0 ñ øàãîì 23\n");
printf("21: Âûâåñòè ÷èñëà ïåðâûõ ôàêòîðèàëîâ\n");
printf("22: Âûâåñòè ÷èñëà N Ôèáîíà÷è\n");
printf("23: Ðàçëîæåíèå ÷èñëà íà ïðîñòûå ìíîæèòåëè\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);
}