Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Високосный год
- ##########################
- #include <cmath>
- #include <iostream>
- using std::cout;
- using std::cin;
- using std::endl;
- int main()
- {
- setlocale(LC_ALL, "RUSSIAN");
- int year;
- cout << "Введите год:" << endl;
- cin >> year;
- if (year % 4 == 0 && year % 100 || year % 100 == 0 && year % 400 == 0)
- cout << year << " — високосный год." << endl;
- else
- cout << year << " — не является високосным годом." << endl;
- }
- ###########################
- Switch. Задача 1
- #include <iostream>
- #include <math.h>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "RUSSIAN");
- int digit;
- cout << "Введите цифру от 0 до 9:" << endl;
- cout << " ";
- cin >> digit;
- cout << " ";
- switch (digit)
- {
- case 0:
- cout << "Ноль." << endl;
- break;
- case 1:
- cout << digit << " — " << "Один." << endl;
- case 2:
- cout << digit << " — " << "Два." << endl;
- break;
- case 3:
- cout << digit << " — " << "Три." << endl;
- break;
- case 4:
- cout << digit << " — " << "Четыре." << endl;
- break;
- case 5:
- cout << digit << " — " << "Пять." << endl;
- break;
- case 6:
- cout << digit << " — " << "Шесть." << endl;
- break;
- case 7:
- cout << digit << " — " << "Семь." << endl;
- break;
- case 8:
- cout << digit << " — " << "Восемь." << endl;
- break;
- case 9:
- cout << digit << " — " << "Девять." << endl;
- break;
- default:
- cout << digit << " — " << "Неизвестная цифра." << endl;
- break;
- }
- }
- ############################################
- Задача про месяц
- #include <iostream>
- #include <math.h>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "RUSSIAN");
- int dd,mm,yy;
- cout << "Введите день" << endl;
- cout << " ";
- cin >> dd;
- cout << "Введите месяц" << endl;
- cout << " ";
- cin >> mm;
- cout << "Введите год" << endl;
- cout << " ";
- cin >> yy;
- cout << dd << "."<< mm <<"." << yy << endl;
- cout << " ";
- switch (mm)
- {
- case 1:
- cout << dd << " " << " января " << " " << yy << " " << " года " << endl;
- break;
- case 2:
- cout << dd << " " << " февраля " << " " << yy << " " << " года " << endl;
- case 3:
- cout << dd << " " << " марта " << " " << yy << " " << " года " << endl;
- break;
- case 4:
- cout << dd << " " << " апреля " << " " << yy << " " << " года " << endl;
- break;
- case 5:
- cout << dd << " " << " мая " << " " << yy << " " << " года " << endl;
- break;
- case 6:
- cout << dd << " " << " июня " << " " << yy << " " << " года " << endl;
- break;
- case 7:
- cout << dd << " " << " июля " << " " << yy << " " << " года " << endl;
- break;
- case 8:
- cout << dd << " " << " августа " << " " << yy << " " << " года " << endl;
- break;
- case 9:
- cout << dd << " " << " сентября " << " " << yy << " " << " года " << endl;
- break;
- case 10:
- cout << dd << " " << " октября " << " " << yy << " " << " года " << endl;
- break;
- case 11:
- cout << dd << " " << " ноября " << " " << yy << " " << " года " << endl;
- break;
- case 12:
- cout << dd << " " << " декабря " << " " << yy << " " << " года " << endl;
- break;
- default:
- cout << dd << "." << mm << "." << yy << " — " << "Неизвестная дата." << endl;
- break;
- }
- }
- #############################################
- Шахматы через SWITCH
- #include <iostream>
- #include <math.h>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "RUSSIAN");
- int x1, y1, x2, y2, n;
- cout << " 0 1 2 3 4 5 6 7 " << endl;
- cout << "7 - * - * - * - * " << endl;
- cout << "6 * - * - * - * - " << endl;
- cout << "5 - * - * - * - * " << endl;
- cout << "4 * - * - * - * - " << endl;
- cout << "3 - * - * - * - * " << endl;
- cout << "2 * - * - * - * - " << endl;
- cout << "1 - * - * - * - * " << endl;
- cout << "0 * - * - * - * - " << endl;
- cout << " " << endl;
- cout << "Выберите фигуру:" << endl;
- cout << " " << endl;
- cout << "1 — СЛОН" << endl;
- cout << "2 — ФЕРЗЬ" << endl;
- cout << "3 — ЛАДЬЯ" << endl;
- cout << "4 — КОНЬ" << endl;
- cout << " " << endl;
- cin >> n;
- switch (n)
- {
- case 1:
- cout << " " << endl;
- cout << "Введите X и Y положения СЛОНА (координаты могут принимать значение от 0 до 7)" << endl;
- cout << " " << endl;
- cin >> x1;
- cin >> y1;
- if (x1 > 7 || y1 > 7) {
- cout << "Точка находится за пределами шахматной доски" << endl; return 0;
- }
- else
- cout << " " << endl;
- cout << "Введите координаты точки M, в которую СЛОН должен пройти (координаты могут принимать значение от 0 до 7)" << endl;
- cout << " " << endl;
- cin >> x2;
- cin >> y2;
- if (x2 > 7 || y2 > 7) {
- cout << "Точка находится за пределами шахматной доски" << endl; return 0;
- }
- else
- if (abs(x1 - x2) == abs(y1 - y2))
- cout << "СЛОН может попасть в точку M" << "(" << x2 << ";" << y2 << ")" << endl;
- else
- cout << "СЛОН не может попасть в точку M" << "(" << x2 << ";" << y2 << ")" << endl;
- break;
- case 2:
- cout << " " << endl;
- cout << " " << endl;
- cout << "Введите X и Y положения ФЕРЗЯ (координаты могут принимать значение от 0 до 7)" << endl;
- cin >> x1;
- cin >> y1;
- if (x1 > 7 || y1 > 7) {
- cout << "Точка находится за пределами шахматной доски" << endl; return 0;
- }
- else
- cout << " " << endl;
- cout << "Введите координаты точки M, в которую ФЕРЗЬ должен пройти (координаты могут принимать значение от 0 до 7)" << endl;
- cout << " " << endl;
- cin >> x2;
- cin >> y2;
- if (x2 > 7 || y2 > 7) {
- cout << "Точка находится за пределами шахматной доски" << endl; return 0;
- }
- else
- if ((x1 == x2 || y1 == y2) || (abs(x1 - x2) == abs(y1 - y2)))
- cout << "ФЕРЗЬ может попасть в точку M" << "(" << x2 << ";" << y2 << ")" << endl;
- else
- cout << "ФЕРЗЬ не может попасть в точку M" << "(" << x2 << ";" << y2 << ")" << endl;
- break;
- case 3:
- cout << " " << endl;
- cout << "Введите X и Y положения ЛАДЬИ (координаты могут принимать значение от 0 до 7)" << endl;
- cout << " " << endl;
- cin >> x1;
- cin >> y1;
- if (x1 > 7 || y1 > 7) {
- cout << "Точка находится за пределами шахматной доски" << endl; return 0;
- }
- else
- cout << " " << endl;
- cout << "Введите координаты точки M, в которую ЛАДЬЯ должна пройти (координаты могут принимать значение от 0 до 7)" << endl;
- cout << " " << endl;
- cin >> x2;
- cin >> y2;
- if (x2 > 7 || y2 > 7) {
- cout << "Точка находится за пределами шахматной доски" << endl; return 0;
- }
- else
- if (x1 == x2 || y1 == y2)
- cout << "ЛАДЬЯ может попасть в точку M" << "(" << x2 << ";" << y2 << ")" << endl;
- else
- cout << "ЛАДЬЯ не может попасть в точку M" << "(" << x2 << ";" << y2 << ")" << endl;
- break;
- case 4:
- cout << " " << endl;
- cout << "Введите X и Y положения КОНЯ (координаты могут принимать значение от 0 до 7)" << endl;
- cout << " " << endl;
- cin >> x1;
- cin >> y1;
- if (x1 > 7 || y1 > 7) {
- cout << "Точка находится за пределами шахматной доски" << endl; return 0;
- }
- else
- cout << " " << endl;
- cout << "Введите координаты точки M, в которую КОНЬ должен пройти (координаты могут принимать значение от 0 до 7)" << endl;
- cout << " " << endl;
- cin >> x2;
- cin >> y2;
- if (x2 > 7 || y2 > 7) {
- cout << "Точка находится за пределами шахматной доски" << endl; return 0;
- }
- else
- if (((x2 == x1 - 1) && (y2 == y1 + 2)) || ((x2 == x1 + 1) && (y2 == y1 + 2)) || ((x2 == x1 + 2) && (y2 == y1 + 1)) || ((x2 == x1 + 2) && (y2 == y1 - 1)) || ((x2 == x1 + 1) && (y2 == y1 - 2)) || ((x2 == x1 - 1) && (y2 == y1 - 2)) || ((x2 == x1 - 2) && (y2 == y1 + 1)) || ((x2 == x1 - 2) && (y2 == y1 - 1)))
- cout << "КОНЬ может попасть в точку M" << "(" << x2 << ";" << y2 << ")" << endl;
- else
- cout << "КОНЬ не может попасть в точку M" << "(" << x2 << ";" << y2 << ")" << endl;
- break;
- }
- return 0;
- }
- #####################################################
- КОЛИЧЕСТВО ДНЕЙ ВАР1
- #include <iostream>
- #include <math.h>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "RUSSIAN");
- int mm;
- cout << "Введите месяц" << endl;
- cout << " ";
- cin >> mm;
- cout << " ";
- switch (mm)
- {
- case 1:
- cout << "Вы ввели — ЯНВАРЬ"<< endl;
- cout << " " << endl;
- cout << "В ЯНВАРЕ 31 день" << endl;
- break;
- case 2:
- cout << "Вы ввели — ФЕВРАЛЬ" << endl;
- cout << " " << endl;
- cout << "В ФЕВРАЛЕ 28 дней" << endl;
- break;
- case 3:
- cout << "Вы ввели — МАРТ" << endl;
- cout << " " << endl;
- cout << "В МАРТЕ 31 день" << endl;
- break;
- case 4:
- cout << "Вы ввели — АПРЕЛЬ" << endl;
- cout << " " << endl;
- cout << "В АПРЕЛЕ 30 дней" << endl;
- break;
- case 5:
- cout << "Вы ввели — МАЙ" << endl;
- cout << " " << endl;
- cout << "В МАЙ 31 день" << endl;
- break;
- case 6:
- cout << "Вы ввели — ИЮНЬ" << endl;
- cout << " " << endl;
- cout << "В ИЮНЕ 30 дней" << endl;
- break;
- case 7:
- cout << "Вы ввели — ИЮЛЬ" << endl;
- cout << " " << endl;
- cout << "В ИЮЛЕ 31 день" << endl;
- break;
- case 8:
- cout << "Вы ввели — АВГУСТ" << endl;
- cout << " " << endl;
- cout << "В АВГУСТЕ 31 дней" << endl;
- break;
- case 9:
- cout << "Вы ввели — СЕНТЯБРЬ" << endl;
- cout << " " << endl;
- cout << "В СЕНТЯБРЕ 30 день" << endl;
- break;
- case 10:
- cout << "Вы ввели — ОКТЯБРЬ" << endl;
- cout << " " << endl;
- cout << "В ОКТЯБРЕ 31 дней" << endl;
- break;
- case 11:
- cout << "Вы ввели — НОЯБРЬ" << endl;
- cout << " " << endl;
- cout << "В НОЯБРЕ 30 день" << endl;
- break;
- case 12:
- cout << "Вы ввели — ДЕКАБРЬ" << endl;
- cout << " " << endl;
- cout << "В ДЕКАБРЕ 31 дней" << endl;
- break;
- default:
- cout << mm << " — " << "Неизвестный месяц" << endl;
- break;
- }
- }
- #####################################
- ЗАДАЧА НА ДНИ ВАР2
- #include <iostream>
- #include <math.h>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "RUSSIAN");
- int mm;
- cout << "Введите месяц" << endl;
- cout << " ";
- cin >> mm;
- cout << " ";
- switch (mm)
- {
- case 1:
- case 3:
- case 5:
- case 7:
- case 8:
- case 10:
- case 12:
- cout << "В этом месяце 31 день" << endl;
- break;
- case 2:
- cout << "В этом месяце 28 дней" << endl;
- break;
- case 4:
- case 6:
- case 9:
- case 11:
- cout << "В этом месяце 30 дней" << endl;
- break;
- default:
- cout << mm << " — " << "Неизвестный месяц" << endl;
- break;
- }
- }
- ############################################
- Задача про алфавит
- #include <iostream>
- #include <math.h>
- using namespace std;
- char main()
- {
- setlocale(LC_ALL, "RUSSIAN");
- char symbol;
- cout << "Введите букву (на латинице)" << endl;
- cout << " ";
- cin >> symbol;
- cout << " ";
- switch (symbol)
- {
- case 'a':
- case 'e':
- case 'i':
- case 'o':
- case 'u':
- case 'y':
- cout << "Эта буква гласная" << endl;
- break;
- case 'b':
- case 'c':
- case 'd':
- case 'f':
- case 'g':
- case 'h':
- case 'k':
- case 'l':
- case 'm':
- case 'n':
- case 'p':
- case 'q':
- case 'r':
- case 's':
- case 't':
- case 'v':
- case 'w':
- case 'x':
- case 'z':
- cout << "Эта согласная буква" << endl;
- break;
- default:
- cout << symbol << " — " << "Неизвестный символ" << endl;
- break;
- }
- }
- ####################################
- калькуцлятор
- #include <iostream>
- #include <math.h>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "RUSSIAN");
- double a,b,S,P,D,V,s,K1,K2;
- int n;
- cout << "Введите первое число." << endl;
- cout << " " << endl;
- cout << "a=";
- cin >> a;
- cout << " " << endl;
- cout << " " << endl;
- cout << "Введите второе число." << endl;
- cout << " " << endl;
- cout << "b=";
- cin >> b;
- cout << " " << endl;
- cout << "Выберите действие: " << endl;
- cout << " " << endl;
- cout << "1 — Сложение" << endl;
- cout << "2 — Произведение" << endl;
- cout << "3 — Деление" << endl;
- cout << "4 — Вычитание" << endl;
- cout << "5 — Возведение в степень" << endl;
- cout << " " << endl;
- cin >> n;
- switch (n)
- {
- case 1:
- S = a + b;
- cout << "Сумма чисел а=" << a << " и " << "b=" << b << " " << "равна: " << " " << S << endl;
- cout << " " << endl;
- break;
- case 2:
- P = a*b;
- cout << "Произведение чисел а=" << a << " и " << "b=" << b << " " << "равно:" << " " << P << endl;
- cout << " " << endl;
- break;
- case 3:
- D = a / b;
- cout << "Деление числа а=" << a << " на " << "число b=" << b << " " << "равно:" << " " << D << endl;
- cout << " " << endl;
- break;
- case 4:
- V = a - b;
- cout << "Вычитание из числа а=" << a << " " << " числа b=" << b << "равно:" << " " << V << endl;
- cout << " " << endl;
- break;
- case 5:
- cout << "Введите степень." << endl;
- cout << "s";
- cin >> s;
- K1 = pow(a,s);
- K2 = pow(b,s);
- cout << "Возведение в степень" <<s<< "числа а=" << K1 << " и " << "Возведение в степень" <<s<< "числа b=" << K2 << endl;
- cout << " " << endl;
- break;
- default:
- cout << a << ", " << b << " — " << "Неверный символ" << endl;
- break;
- }
- }
- ######################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement