Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int TakeNum(const int MIN, const int MAX) {
- const string ERROR_CHOISE = "Проверьте корректность введнных данных!\n";
- bool isIncorrect;
- int num;
- do {
- isIncorrect = false;
- cin >> num;
- if (cin.fail()) {
- isIncorrect = true;
- cout << ERROR_CHOISE;
- cin.clear();
- while (cin.get() != '\n');
- }
- if (!isIncorrect && cin.get() != '\n') {
- cin.clear();
- while (cin.get() != '\n');
- cout << ERROR_CHOISE;
- isIncorrect = true;
- }
- if (!isIncorrect && (num < MIN || num > MAX)) {
- isIncorrect = true;
- cout << ERROR_CHOISE;
- }
- } while (isIncorrect);
- return num;
- }
- // function for the second task
- void swap(int *x, int *y) {
- int temp = *x;
- *x = *y;
- *y = temp;
- }
- // function for the fourth task
- void amstrongNumber(int k, int& first, int& second) {
- int count = 0, temp, sum, digit, i, j = 0;
- bool isTwo = false;
- for(int i = 11; i < k + 1; i++) {
- sum = 0;
- count = 0;
- temp = i;
- while (temp > 0) {
- temp /= 10;
- count++;
- }
- temp = i;
- while (temp > 0) {
- digit = temp % 10;
- sum += pow(digit, count);
- temp /= 10;
- }
- if (sum == i && j == 0) {
- first = sum;
- j++;
- }
- else if (sum == i && j == 1) {
- second = sum;
- j++;
- }
- }
- }
- int main() {
- setlocale(LC_ALL, "");
- // First task
- cout << "Задание 1\n";
- long value1 = 200000, value2;
- long* yk = &value1;
- cout << *yk << endl;
- value2 = *yk;
- cout << value2 << endl;
- cout << &value1 << endl;
- cout << yk << endl;
- // Second task
- cout << "\nЗадание 2\n";
- int a = 3, b = 5;
- swap(a, b);
- cout << a << " and " << b << endl;
- // Third task
- cout << "\nЗадание 3\n";
- int* Ptr;
- a = 7; Ptr = &a;
- cout << "Адрес а = " << & a << "\nЗначение указателя Ptr = " << Ptr;
- cout << "\nЗначение а = " << a << "\nЗначение, нак которое указывает Ptr = " << *Ptr;
- cout << "\n&*Ptr = " << &*Ptr << "\n*&Ptr = " << *&Ptr << endl;
- // Fourth task
- cout << "\nЗадание 4\n";
- int k = 500, first = 0, second = 0;
- amstrongNumber(k, first, second);
- if (first == 0 && second == 0)
- cout << "В данном диапазоне таких чисел нет";
- else if (first != 0 && second == 0)
- cout << "В данном диапазоне только одно число Амстронга = " << first;
- else
- cout << "В данном диапазоне первое число Амстронга = " << first << ", а второе = " << second;
- }
Advertisement
Add Comment
Please, Sign In to add comment