Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
♻️ (Bai 071, 101): Refractor from Tien
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinNitroG committed Nov 14, 2023
1 parent 5d321c7 commit c84ab15
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 42 deletions.
44 changes: 21 additions & 23 deletions Bai071/Source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,33 @@
#include <iomanip>
using namespace std;

void Input(float[], int&);
void Enumerate(float[], int);
void Input(float[], int &);
void LietKe(float[], int);
void Output(float[], int);

int main()
{
int n = 0;
while (n <= 0)
{
cout << "\nEnter n: ";
cin >> n;
}
float* arr = new float[n];
int n;
cout << "Nhap n: ";
cin >> n;

float arr[100];
Input(arr, n);
cout << "\nYour inputted array is:" << endl;

cout << "Array vua nhap:" << endl;
Output(arr, n);
cout << "\nAll the negative elements in the inputted array:" << endl;
Enumerate(arr, n);
delete[]arr;
cout << endl;
return 1;

cout << "Array cac so am:" << endl;
LietKe(arr, n);

return 0;
}

void Input(float arr[], int& n)
void Input(float arr[], int &n)
{
cout << "\nYour inputted array will have " << n << " elements." << endl;
for (int i = 0; i < n; i++)
{
cout << "Enter arr[" << i << "] element: ";
cout << "arr[" << i << "]:";
cin >> arr[i];
}
}
Expand All @@ -41,16 +39,16 @@ void Output(float arr[], int n)
{
if (i % 20 == 0 && i != 0)
cout << endl;
cout << setw(10) << setprecision(6) << arr[i];
cout << setw(10) << setprecision(3) << arr[i];
}
cout << endl;
}

void Enumerate(float arr[], int n)
void LietKe(float arr[], int n)
{
if (n == 0)
return;
Enumerate(arr, n - 1);
if (arr[n - 1] < 0)
cout << setw(10) << setprecision(6) << arr[n - 1];
LietKe(arr, n - 1);
if (arr[n - 1] < 0)
cout << setw(10) << setprecision(3) << arr[n - 1];
}
33 changes: 14 additions & 19 deletions Bai101/Source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,29 @@
#include <iomanip>
using namespace std;

void Input(int[], int&);
void Input(int[], int &);
void Output(int[], int);
bool PerfNumChk(int);
int PerfNumCount(int[], int);

int main()
{
int n = 0;
while (n <= 0)
{
cout << "\nEnter n: ";
cin >> n;
}
int* arr = new int[n];
int n;
cout << "Nhap n";
cin >> n;

int *arr = new int[n];
Input(arr, n);
cout << "\nYour inputted array is:" << endl;
cout << "Array vua nhap:" << endl;
Output(arr, n);
int counter = PerfNumCount(arr, n);
cout << "The number of perfect number in the inputted array is: " << counter << ".";
delete[]arr;
cout << endl;
return 1;

cout << "So cac so hoan thien trong array: " << PerfNumCount(arr, n) << endl;

delete[] arr;
return 0;
}

void Input(int arr[], int& n)
void Input(int arr[], int &n)
{
cout << "\nYour inputted array will have " << n << " elements." << endl;
for (int i = 0; i < n; i++)
Expand Down Expand Up @@ -60,8 +58,5 @@ int PerfNumCount(int arr[], int n)
{
if (n == 0)
return 0;
int counter = PerfNumCount(arr, n - 1);
if (PerfNumChk(arr[n - 1]) == true)
counter++;
return counter;
return PerfNumCount(arr, n - 1) + (PerfNumChk(arr[n - 1]) ? 1 : 0);
}

0 comments on commit c84ab15

Please sign in to comment.