-
Notifications
You must be signed in to change notification settings - Fork 0
push homework 4 #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| /* | ||
| * Домашнее задание к уроку 4 | ||
| * курса "Основы языка С++" | ||
| * автор Недокунев А.В. | ||
| * среда разработки Notepad++ /компилятор MinGW/ | ||
| * codepage UTF-8 | ||
| */ | ||
| #include <iostream> | ||
|
|
||
| int check_simple(int number){//для задания 2 | ||
| if (number == 0 || number == 1 || number % 2 == 0){//числа 0, 1 и четные - не простые | ||
| return 0; | ||
| } | ||
| if (number == 2){//2 - простое | ||
| return 1; | ||
| } | ||
| for (int i = 3; i * i < number; i += 2){//если число не делится на 2, то оно неподелится и на другое четное | ||
| if (number % i == 0){ | ||
| return 0; | ||
| } | ||
| } | ||
| return 1; | ||
| } | ||
|
|
||
| int main(){ | ||
| /*Задание 1 | ||
| Написать программу, проверяющую что сумма двух чисел | ||
| лежит в пределах от 10 до 20 (включительно), | ||
| если да – вывести true, в противном случае – false;*/ | ||
|
|
||
| int a, b; | ||
| std::cout << "Введите первое число" << std::endl; | ||
| std::cin >> a; | ||
| std::cout << "Введите второе число" << std::endl; | ||
| std::cin >> b; | ||
| if ((a + b >= 10) && (a + b <= 20)) { | ||
| std::cout << "true" << std::endl; | ||
| } else { | ||
| std::cout << "false" << std::endl; | ||
| } | ||
|
|
||
|
|
||
| /*Задание 2 | ||
| Написать программу, проверяющую, является ли некоторое число - | ||
| натуральным простым. Простое число - это число, | ||
| которое делится без остатка только на единицу и себя само.*/ | ||
|
|
||
| int number = -1, simple = 1; | ||
| while (number < 0){//натуральное - значит целое положительное | ||
| std::cout << "Введите число" << std::endl; | ||
| std::cin >> number; | ||
| } | ||
| if (check_simple(number)){ | ||
| std::cout << "Простое число" << std::endl; | ||
| } else { | ||
| std::cout << "Составное число" << std::endl; | ||
| } | ||
|
|
||
| /*Задание 3 | ||
| Написать программу, выводящую на экран “истину”, | ||
| если две целочисленные константы, объявленные в её начале | ||
| либо равны десяти сами по себе, либо их сумма равна десяти.*/ | ||
| const int a1 = 9, a2 = 100; | ||
| if (a1 == 10 || a2 == 10 || a1 + a2 == 10){//если я правильно понял условия или | ||
| // if ((a1 == 10 && a2 == 10) || a1 + a2 ==10{ //если неправильно | ||
| std::cout << "ИСТИНА" << std::endl; | ||
| } | ||
|
|
||
|
|
||
| /*Задание 4* | ||
| Написать программу, которая определяет является ли год високосным. | ||
| Каждый 4-й год является високосным, | ||
| кроме каждого 100-го, при этом каждый 400-й – високосный. | ||
| Для проверки работы вывести результаты работы программы в консоль*/ | ||
| int year, leap = 0; | ||
| std::cout << "Введите год" << std::endl; | ||
| std::cin >> year; | ||
| if (year%4 == 0){ | ||
| if (year%400 == 0){ | ||
| leap = 1; | ||
| } else if (year%100 == 0){ | ||
| leap = 0; | ||
| } else { | ||
| leap = 1; | ||
| } | ||
| } else { | ||
| leap = 0; | ||
| } | ||
| if (leap) { | ||
| std::cout << "високосный" << std::endl; | ||
| } else { | ||
| std::cout << "НЕ високосный" << std::endl; | ||
| } | ||
|
|
||
|
|
||
| return 0; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
можно объединить в одно длинное условие, сократим много строк и не ухудшим читаемость