Created
September 15, 2024 12:39
-
-
Save Darklega228/b4f90703853725124d755ef3213e9890 to your computer and use it in GitHub Desktop.
This file contains 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
#include <iostream> | |
#include <windows.h> | |
#include <string> | |
using namespace std; | |
// ДЗ 1 | |
//Задание 1 | |
/*double Stepeni(double base, int setepn) | |
{ | |
return pow(base, setepn); | |
} | |
int main() | |
{ | |
setlocale(0, ""); | |
double base; | |
int setepn; | |
cout << "Введите основу степени: "; | |
cin >> base; | |
cout << "Введите показатель степени: "; | |
cin >> setepn; | |
double result = Stepeni(base, setepn); | |
cout << "Результат: " << result << endl; | |
return 0; | |
}*/ | |
// Задание 2 | |
/*int Suma(int first, int second) | |
{ | |
int sum = 0; | |
if(first > second) | |
{ | |
swap(first, second); | |
} | |
for (int i = first; i <= second; ++i) | |
{ | |
sum += i; | |
} | |
return sum; | |
} | |
int main() | |
{ | |
setlocale(0, ""); | |
int first, second; | |
cout << "Введите первое число: "; | |
cin >> first; | |
cout << "Введите второе число: "; | |
cin >> second; | |
int result = Suma(first, second); | |
cout << "Сумма чисел в диапазоне: " << result << endl; | |
return 0; | |
}*/ | |
// Задание 3 | |
/*bool Doskonalui(int num) | |
{ | |
int sum = 0; | |
for (int i = 1; i <= num / 2; ++i) | |
{ | |
if(num % i == 0) | |
{ | |
sum += i; | |
} | |
} | |
return sum==num; | |
} | |
void FindDoskonalui(int first, int second) | |
{ | |
cout << "Совершенные числа [" << first << ", " << second << "]" << endl; | |
for(int i = first; i <= second; ++i) | |
{ | |
if(Doskonalui(i)) | |
{ | |
cout << i << " "; | |
} | |
} | |
cout << endl; | |
} | |
int main() | |
{ | |
setlocale(0, ""); | |
int first, second; | |
cout << "Введите начало интервала: "; | |
cin >> first; | |
cout << "Введите конец интервала: "; | |
cin >> second; | |
FindDoskonalui(first, second); | |
return 0; | |
}*/ | |
// Задание 4 | |
/*void Kartu(const string suit, const string value) | |
{ | |
cout << "Игральная карта: " << value << " of " << suit << endl; | |
} | |
int main() | |
{ | |
setlocale(0, ""); | |
string suit, value; | |
cout << "Введите масть карты (например, Hearts, Diamonds, Clubs, Spades): "; | |
getline(cin, suit); | |
cout << "Введите чилсо/букву карты (наприклад, 2, 3, 4, ..., 10, J, Q, K, A): "; | |
getline(cin, value); | |
Kartu(suit, value); | |
return 0; | |
}*/ | |
//Задание 5 | |
int Suma(int num) | |
{ | |
int sum = 0; | |
while (num > 0) | |
{ | |
sum += num % 10; | |
num /= 10; | |
} | |
return sum; | |
} | |
bool LuckNum(int number) | |
{ | |
if (number < 100000 || number > 999999) | |
{ | |
return false; | |
} | |
int firstHalf = number / 1000; | |
int secondHalf = number % 1000; | |
return Suma(firstHalf) == Suma(secondHalf); | |
} | |
int main() | |
{ | |
setlocale(0, ""); | |
int number; | |
cout << "Введите шестизначное число: "; | |
cin >> number; | |
if (LuckNum(number)) | |
{ | |
cout << "Щасливое число" << endl; | |
} | |
else | |
{ | |
cout << number << " Не щасливое число" << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment