Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Задача 1)
- #include <iostream>
- using namespace std;
- int main()
- {
- int i, n;
- cout << "Number n: ";
- cin >> n;
- i = 1;
- while (i <= n) {
- cout << i << endl;
- i++;
- }
- }
- =====================================
- Задача 2)
- #include <iostream>
- using namespace std;
- int main()
- {
- int n;
- cout << "Number n: ";
- cin >> n;
- int i = 1, sum = 0;
- while (i <= n) {
- sum += i;
- i++;
- }
- cout << "Total sum: " << sum << endl;
- }
- =====================================
- Задача 3)
- #include <iostream>
- using namespace std;
- int main()
- {
- int n, i = 1;
- cout << "Number n: ";
- if (n <= 0){
- cout << "No numbers!";
- n = 1;
- }
- cin >> n;
- while (i < n) {
- if (i % 2 == 0)
- cout << i << endl;
- i++;
- }
- }
- =====================================
- Задача 4)
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main()
- {
- int x, y, power;
- cout << "x: ";
- cin >> x;
- cout << "y: ";
- cin >> y;
- power = 1;
- while (pow(x, power) < y){
- cout << power << endl;
- power ++;
- }
- }
- =====================================
- Задача 5)
- #include <iostream>
- using namespace std;
- int main()
- {
- int num, sum;
- cout << "Number: ";
- cin >> num;
- while (num != 0){
- sum += num;
- cout << "Number: ";
- cin >> num;
- }
- cout << "Total sum: " << sum;
- }
- =====================================
- Задача 6)
- #include <iostream>
- using namespace std;
- int main()
- {
- int num, mul = 1;
- cout << "Number: ";
- cin >> num;
- while (num != 0){
- mul *= num;
- cout << "Number: ";
- cin >> num;
- }
- cout << "Total multiplication: " << mul;
- }
- =====================================
- Задача 7)
- #include <iostream>
- using namespace std;
- int main()
- {
- int num, count;
- cout << "Number: ";
- cin >> num;
- while (num != 0){
- count += 1;
- cout << "Number: ";
- cin >> num;
- }
- cout << "Total count: " << count;
- }
- =====================================
- Задача 8)
- #include <iostream>
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- vector<int> numbers;
- int n;
- cout << "Number n: ";
- cin >> n;
- while (n != 0){
- numbers.push_back(n);
- cout << "Number n: ";
- cin >> n;
- }
- cout << "Max Element: " << *max_element(numbers.begin(), numbers.end()) << endl;
- cout << "Min Element: " << *min_element(numbers.begin(), numbers.end());
- return 0;
- }
- =====================================
- Задача 9)
- #include <iostream>
- using namespace std;
- int main()
- {
- int num, possitvie_counter = 1;
- while (possitvie_counter <= 3){
- cout << "Enter a number: ";
- cin >> num;
- if (num > 0)
- possitvie_counter++;
- }
- cout << "You've entered 3 possitive numbers: " << possitvie_counter;
- return 0;
- }
- =====================================
- Задача 10)
- Начин 1)
- #include <iostream>
- using namespace std;
- int main() {
- int n, reversedNumber = 0, remainder;
- cout << "Enter an integer: ";
- cin >> n;
- while(n != 0) {
- remainder = n%10;
- reversedNumber = reversedNumber*10 + remainder;
- n /= 10;
- }
- cout << "Reversed Number = " << reversedNumber;
- return 0;
- }
- Начин 2)
- #include <iostream>
- #include <sstream>
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int num;
- cout << "Enter a number: ";
- cin >> num;
- stringstream ss;
- ss << num;
- string number_to_str;
- ss >> number_to_str;
- reverse(number_to_str.begin(), number_to_str.end());
- cout << "The number " << num << " in reversed is " + number_to_str;
- return 0;
- }
- =====================================
- Задача 11)
- #include <iostream>
- using namespace std;
- int main()
- {
- int num, sum = 0, int_char;
- cout << "Enter a number: ";
- cin >> num;
- while (num > 0) {
- int_char = num % 10;
- sum = sum + int_char;
- num = num / 10;
- }
- cout << "Sum is: " << sum << endl;
- return 0;
- }
- =====================================
- Задача 12)
- #include <iostream>
- using namespace std;
- int main()
- {
- int num, num_numerical = 0, int_char;
- cout << "Enter a number: ";
- cin >> num;
- while (num > 0) {
- int_char = num % 10;
- num = num / 10;
- num_numerical++;
- }
- cout << "Number numerical: " << num_numerical << endl;
- return 0;
- }
- =====================================
- Задача 13)
- #include <iostream>
- using namespace std;
- int main()
- {
- int num, reversed_num = 0, remainder, sum, num_copy;
- cout << "Enter an number: ";
- cin >> num;
- num_copy = num;
- while(num != 0) {
- remainder = num % 10;
- reversed_num = reversed_num * 10 + remainder;
- num /= 10;
- }
- cout << "Reversed Number = " << reversed_num << endl << endl;
- sum = (num_copy + reversed_num);
- cout << "The sum of the 2 numbers is: " << sum;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment