-
Notifications
You must be signed in to change notification settings - Fork 2
Glagolev ruslan request to check homework2 #17
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
base: master
Are you sure you want to change the base?
Changes from all commits
a0f6ce1
c47e95c
4cc4859
f82749a
b44a874
d3f4e97
9d454f9
b2c1f81
f663015
a472a0a
896028a
585db47
f316094
f672cbc
dee8aef
af07e36
977aa85
52a9ebd
4c48332
a02fac0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #include <iostream> | ||
|
|
||
| int main() { | ||
| int number; | ||
| int sum = 0; | ||
| int count_digit_in_number = 0; | ||
|
|
||
| std::cout << "Please enter any number, this program will calculate the sum " | ||
| "of the\n"; | ||
| std::cout << "digits in the number, and Arithmetic mean of the digits of " | ||
| "your number-"; | ||
| std::cin >> number; | ||
|
|
||
| while (number != 0) { | ||
| sum += number % 10; | ||
| number /= 10; | ||
| count_digit_in_number++; | ||
| } | ||
| auto avarage = static_cast<double>(sum) / count_digit_in_number; | ||
| std::cout << "The sum of the digits of your number- " << sum << std::endl; | ||
| std::cout << "Arithmetic mean of the digits of your number - " << avarage | ||
| << std::endl; | ||
|
|
||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| #include <iostream> | ||
|
|
||
| int main() { | ||
| int number; | ||
| int first_half_of_the_number = 0; | ||
| int second_half_of_the_number = 0; | ||
| int count_digit_in_number = 0; | ||
| std::cout << "This program calculates whether your ticket is successful or " | ||
| "unsuccessful!\n"; | ||
| std::cout << "Enter a six-digit number-" << std::endl; | ||
| std::cin >> number; | ||
| while (number != 0) { | ||
| int check_the_number_of_digits = 0; | ||
| int c = number; | ||
| while (c != 0) { | ||
| c /= 10; | ||
| check_the_number_of_digits++; | ||
| } | ||
| if (check_the_number_of_digits != 6) { | ||
| std::cout << "The number is not six-digit, enter the six-digit number-" | ||
| << std::endl; | ||
| std::cin >> number; | ||
| } | ||
MykolaSuperman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| break; | ||
| } | ||
| while (count_digit_in_number < 3) { | ||
| first_half_of_the_number += number % 10; | ||
| number /= 10; | ||
| count_digit_in_number++; | ||
| } | ||
MykolaSuperman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| while (number != 0) { | ||
| second_half_of_the_number += number % 10; | ||
| number /= 10; | ||
| } | ||
| if (second_half_of_the_number == first_half_of_the_number) { | ||
| std::cout << "Your ticket is successful"; | ||
| } else { | ||
| std::cout << "Your ticket is no unsuccessful"; | ||
| } | ||
| return 0; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #include <cmath> | ||
MykolaSuperman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #include <iostream> | ||
|
|
||
| int main() { | ||
| int normal_number; | ||
| int check_number; | ||
| int multiplicity_of_number = 1; | ||
| auto reverse_number = 0; | ||
| std::cout << "This program reverses the digits of your number in places.\n"; | ||
| std::cout << "Enter your number-"; | ||
| std::cin >> normal_number; | ||
| check_number = abs(normal_number); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. вот например тут, зачем вверху обьявлять переменную |
||
| while (check_number != 0) { | ||
| check_number /= 10; | ||
| multiplicity_of_number *= 10; | ||
| if (check_number > 0 && check_number < 9) { | ||
| check_number = 0; | ||
| } | ||
| } | ||
MykolaSuperman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| while (normal_number != 0) { | ||
| reverse_number = | ||
| reverse_number + multiplicity_of_number * (normal_number % 10); | ||
| normal_number /= 10; | ||
| multiplicity_of_number /= 10; | ||
| } | ||
| std::cout << "reverse number-" << reverse_number; | ||
| return 0; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #include <iostream> | ||
|
|
||
| int main() { | ||
| auto sum = 0; | ||
| int number_of_digits = 1; | ||
| size_t max_iteration{50}; | ||
| std::cout << "This program calculates the sum of odd numbers in the range \n"; | ||
| std::cout << "from -60 to 90, and you can enter no more than 50 numbers." | ||
| << std::endl; | ||
| while (max_iteration > 0) { | ||
| int number; | ||
| std::cout << "Enter number " << number_of_digits << ":" << std::endl; | ||
| std::cin >> number; | ||
| if (number >= -60 && number <= 90) { | ||
| if (number % 2 != 0) { | ||
| sum += number; | ||
| } | ||
|
|
||
| ++number_of_digits; | ||
MykolaSuperman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| --max_iteration; | ||
| } | ||
MykolaSuperman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| std::cout << "Sum of odd elements- " << sum; | ||
| return 0; | ||
| } | ||
MykolaSuperman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #include <iostream> | ||
|
|
||
| int main() { | ||
| long long number; | ||
| long long divisor = 0; | ||
| long long best_sum_number_divisor = 0; | ||
| long long sum_number_divisor = 0; | ||
| long long divisor_1; | ||
| long long best_divisor; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. вот зачем обьявлять все тут переменные??? как думаете удобно смотреть весь список переменных в начале, а потом искать по всему коду где же они применяються. Приучайтесь создавать переменные(обьявлять), перед первым их использованием. Не надо все переменные создавать в начале, а потом ниже в коде их инициализировать, так никто не пишет |
||
| std::cout << "This program calculates the best divisor of your number, as " | ||
| "well as the best divisor,\n"; | ||
| std::cout << "based on the sum of the divisor.\n"; | ||
| std::cout << "Enter tour number- "; | ||
| std::cin >> number; | ||
| for (long long i = 1; i <= number; ++i) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. вместо типа |
||
| if (number % i == 0) { | ||
| std::cout << "Divisor- " << i << "\n"; | ||
| if (divisor < i) { | ||
| divisor = i; | ||
| } | ||
| divisor_1 = divisor; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. например зачем выносить в начале |
||
| while (divisor_1 > 0) { | ||
| sum_number_divisor += divisor_1 % 10; | ||
| divisor_1 /= 10; | ||
| } | ||
| if (sum_number_divisor > best_sum_number_divisor) { | ||
| best_sum_number_divisor = sum_number_divisor; | ||
| sum_number_divisor = 0; | ||
| best_divisor = divisor; | ||
| } | ||
| } | ||
| } | ||
| std::cout << "The best divisor your number- " << best_divisor << std::endl; | ||
| std::cout << "The best divisor by the sum of the digits -" << best_divisor; | ||
| return 0; | ||
| } | ||
MykolaSuperman marked this conversation as resolved.
Show resolved
Hide resolved
MykolaSuperman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #include <iostream> | ||
|
|
||
| int main() { | ||
| int number; | ||
| int skimmer = 0; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. название переменной огонь) |
||
| std::cout << "This program draws a Christmas tree with the symbol '*', which " | ||
| "will be based on the number you specify.\n"; | ||
| std::cout << "You need to enter only odd numbers from 0 to 100." << std::endl; | ||
| std::cout << "Enter your number-"; | ||
| std::cin >> number; | ||
| while (number % 2 == 0 || number < 0 || number > 100) { | ||
| std::cout << "Enter the correct number- "; | ||
| std::cin >> number; | ||
| } | ||
| for (int a = 0; a != (number + 1) / 2; a++) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. вместо |
||
| for (int i = 0; i < number; i++) { | ||
MykolaSuperman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| int max = i + skimmer; | ||
| int min = i - skimmer; | ||
| if (max >= number / 2 && min <= number / 2) { | ||
| std::cout << "*"; | ||
| } else { | ||
| std::cout << " "; | ||
| } | ||
| } | ||
| std::cout << "\n"; | ||
| skimmer++; | ||
| } | ||
| return 0; | ||
| } | ||
MykolaSuperman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.
обьявляйте переменные по мере их использования, вот зачем тут обьявлять переменные
first_half_of_the_numberиsecond_half_of_the_numberесли реально они будут применяться только после того как вы проверите коректность введенного числа, т.е. проверка что число содержит 6 цифр