Комп сгорел, дз надо делать Решение + **** 1. Вывести на экран числа в промежутке (0; 100). 2. Пользователь вводит текст. Посчитать количество введенных символов, вывести число на экран. 3. Пользователь вводит текст. Посчитать количество введенных БОЛЬШИХ символов, вывести число на экран. 4. Пользователь вводит 2 числа (например назовем их a i b). Посчитать сумму всех чисел в полученном промежутке (начиная от а и заканчивая b). 5. Пользователь вводит текст. Посчитать количество введенных маленьких символов, вывести число на экран. 6. Вывести на экран числа в промежутке (100; 0). 7. Пользователь вводит 2 числа (например назовем их a i b). Посчитать произведение всех чисел в полученном промежутке (начиная от а и заканчивая b). 8. Пользователь вводит текст. Посчитать количество введенных слов. Вывести число на экран. Код 1. Вывести на экран числа в промежутке (0; 100). 2. Пользователь вводит текст. Посчитать количество введенных символов, вывести число на экран. 3. Пользователь вводит текст. Посчитать количество введенных БОЛЬШИХ символов, вывести число на экран. 4. Пользователь вводит 2 числа (например назовем их a i b). Посчитать сумму всех чисел в полученном промежутке (начиная от а и заканчивая b). 5. Пользователь вводит текст. Посчитать количество введенных маленьких символов, вывести число на экран. 6. Вывести на экран числа в промежутке (100; 0). 7. Пользователь вводит 2 числа (например назовем их a i b). Посчитать произведение всех чисел в полученном промежутке (начиная от а и заканчивая b). 8. Пользователь вводит текст. Посчитать количество введенных слов. Вывести число на экран.
1. #include <iostream> using namespace std; void main() { //задаём русский язык для консоли setlocale(LC_ALL, "Russian"); long sum = 0; int a; cout << "Введите a" << endl; cin >> a; if (a > 500) { cout << "а > 500" << endl; } else { sum = (500 * 501 / 2) - ((a - 1) * a ) / 2; cout << sum; } } 2. #include <iostream> using namespace std; void main() { //задаём русский язык для консоли setlocale(LC_ALL, "Russian"); double average = (1 + 1000) / 2.; cout << "Среднее арифметические чисел от 1 до 1000" << average << endl; } 3 #include <iostream> using namespace std; void main() { //задаём русский язык для консоли setlocale(LC_ALL, "Russian"); int a = 0, b = 0; cout << "Введите границы диапазона" << endl; cin >> a >> b; cout << "Все числа:" << endl; if (a <= b) { for (int i = a; i <= b; i++) { cout << i << endl; } } else { for (int i = b; i < a; i++) { cout << i << endl; } } cout << "Чётные числа:" << endl; if (a <= b) { for (int i = a; i <= b; i++) { if (i % 2 == 0) { cout << i << endl; } } } else { for (int i = b; i < a; i++) { if (i % 2 == 0) { cout << i << endl; } } } cout << "Нечётные числа:" << endl; if (a <= b) { for (int i = a; i <= b; i++) { if (i % 2 != 0) { cout << i << endl; } } } else { for (int i = b; i < a; i++) { if (i % 2 != 0) { cout << i << endl; } } } cout << "Числа, кратные 7:" << endl; if (a <= b) { for (int i = a; i <= b; i++) { if (i % 7 == 0) { cout << i << endl; } } } else { for (int i = b; i < a; i++) { if (i % 7 == 0) { cout << i << endl; } } } } 4. #include <iostream> using namespace std; void main() { //задаём русский язык для консоли setlocale(LC_ALL, "Russian"); int a = 0, sum = 0; cout << "Введите числа" << endl; while (true) { cin >> a; if (a == 0) { break; } sum += a; } cout << "Сумма =" << sum << endl; } Подробнее - на Znanija.com - https://znanija.com/task/16089081#readmore
1 задание int main() { for(int i = 1; i <= 100; ++i) { if( !(i % 3) || std::to_string(i).find('3') != std::string::npos ) { continue; } std::cout << i << ' '; } std::cout << std::endl; } Код int main() { for(int i = 1; i <= 100; ++i) { if( !(i % 3) || std::to_string(i).find('3') != std::string::npos ) { continue; } std::cout << i << ' '; } std::cout << std::endl; }
#include <iostream> #include <string> #include <algorithm> #include <cassert> void task_2() { std::string str; std::cout << "Input a text: "; std::getline(std::cin, str); //Если пробел учитывать не нужно. const int count = std::count_if(str.begin(), str.end(), [](char c) { return !isspace(c); }); std::cout << "Symbols count: " << str.length(); // Если пробел учитывается } void task_4() { int begin, end; std::cout << "begin = "; std::cin >> begin; std::cout << "end = "; std::cin >> end; assert(end > begin); const int sumInRange = ((begin + end) * (end - begin + 1)) / 2; //Сумма арифметической прогрессии. std::cout << "Sum in range between " << begin << " and " << end << " equals to " << sumInRange; } void task_5() { std::string str; std::cout << "Input a text: "; std::getline(std::cin, str); const int count = std::count_if(str.begin(), str.end(), [](char c) { return islower(c); }); std::cout << "Lowercase symbols count: " << count; } void task_6() { for (int i = 100; i >= 0; --i) { std::cout << i << " "; } } void task_7() { int begin, end; std::cout << "begin = "; std::cin >> begin; std::cout << "end = "; std::cin >> end; assert(end > begin); int res = 1; for (int i = begin; i <= end; ++i) { res *= i; } std::cout << "Multiplication of numbers in range between " << begin << " and " << end << " equals to " << res; } void task_8() { std::string str; std::cout << "Input a text: "; std::getline(std::cin, str); int wordsCount = 1; for (std::size_t i = 0; i < str.length() - 1; ++i) { if (isspace(str[i]) && !isspace(str[i + 1])) { ++wordsCount; } } if (isspace(str.back())) { --wordsCount; } if (!isspace(str.front())) { ++wordsCount; } std::cout << "Words count: " << wordsCount; } Код #include <iostream> #include <string> #include <algorithm> #include <cassert> void task_2() { std::string str; std::cout << "Input a text: "; std::getline(std::cin, str); //Если пробел учитывать не нужно. const int count = std::count_if(str.begin(), str.end(), [](char c) { return !isspace(c); }); std::cout << "Symbols count: " << str.length(); // Если пробел учитывается } void task_4() { int begin, end; std::cout << "begin = "; std::cin >> begin; std::cout << "end = "; std::cin >> end; assert(end > begin); const int sumInRange = ((begin + end) * (end - begin + 1)) / 2; //Сумма арифметической прогрессии. std::cout << "Sum in range between " << begin << " and " << end << " equals to " << sumInRange; } void task_5() { std::string str; std::cout << "Input a text: "; std::getline(std::cin, str); const int count = std::count_if(str.begin(), str.end(), [](char c) { return islower(c); }); std::cout << "Lowercase symbols count: " << count; } void task_6() { for (int i = 100; i >= 0; --i) { std::cout << i << " "; } } void task_7() { int begin, end; std::cout << "begin = "; std::cin >> begin; std::cout << "end = "; std::cin >> end; assert(end > begin); int res = 1; for (int i = begin; i <= end; ++i) { res *= i; } std::cout << "Multiplication of numbers in range between " << begin << " and " << end << " equals to " << res; } void task_8() { std::string str; std::cout << "Input a text: "; std::getline(std::cin, str); int wordsCount = 1; for (std::size_t i = 0; i < str.length() - 1; ++i) { if (isspace(str[i]) && !isspace(str[i + 1])) { ++wordsCount; } } if (isspace(str.back())) { --wordsCount; } if (!isspace(str.front())) { ++wordsCount; } std::cout << "Words count: " << wordsCount; }
Опечатка в восьмом (task_8()): Правильный вариант void task_8() { std::string str; std::cout << "Input a text: "; std::getline(std::cin, str); int wordsCount = 0; for (std::size_t i = 0; i < str.length() - 1; ++i) { if (isspace(str[i]) && !isspace(str[i + 1])) { ++wordsCount; } } if (!isspace(str.front())) { ++wordsCount; } std::cout << "Words count: " << wordsCount; } Код void task_8() { std::string str; std::cout << "Input a text: "; std::getline(std::cin, str); int wordsCount = 0; for (std::size_t i = 0; i < str.length() - 1; ++i) { if (isspace(str[i]) && !isspace(str[i + 1])) { ++wordsCount; } } if (!isspace(str.front())) { ++wordsCount; } std::cout << "Words count: " << wordsCount; }