Professional Documents
Culture Documents
de 5-đã chuyển đổi
de 5-đã chuyển đổi
#include <ctime>
using namespace std;
struct node
{
int data;
struct node* pLeft;
struct node* pRight;
};
typedef struct node NODE;
typedef NODE* TREE;
void khoiTaoCay(TREE& t)
{
t = NULL;
}
bool check_So_ArmStrong(int n)
{
int temp;
int tong = 0;
int copy_of_num = n;
while (n > 0)
{
temp = n % 10;
tong = tong + (temp * temp * temp);
if (tong == copy_of_num)
{
return true;
}
n /= 10;
}
return false;
}
void duyetCay_NLR(TREE t)
{
if (t != NULL)
{
cout << t->data << "\t ";
duyetCay_NLR(t->pLeft);
duyetCay_NLR(t->pRight);
}
}
int nhapn() {
int n;
do {
cout << "Nhap so nguyen: ";
cin >> n;
if (n >= 1 && n <= 1000) return n;
} while (true);
}
int main() {
TREE t;
khoiTaoCay(t);
cout << "CAU 1 :\n";
int n;
n = nhapn();
cout << "\n CAU 2 :\n";
taoCayVoiGiaTriNgauNhien(t, n);
duyetCay_NLR(t);
cout << "\nCAU 3 :\n";
int tong, dem;
tinhTong_So_ArmStrong(t, tong);
dem_So_ArmStrong(t, dem);
cout << dem<<endl;
cout << tong << endl;
if (dem == 0) {
cout << "khong ton tai so Amstrong ";
}
else {
cout << "Gia Tri TBC Cua So AmStrong La : " << (float)tong / dem;
}
system("pause");