This repository has been archived by the owner on Feb 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
17557c7
commit 7132877
Showing
2 changed files
with
77 additions
and
6 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,37 @@ | ||
#include <iostream> | ||
#include<iostream> | ||
#include<iomanip> | ||
using namespace std; | ||
int DauTien(int[], int); | ||
void Nhap(int a[], int& n); | ||
|
||
int main() | ||
{ | ||
|
||
int a[100]; | ||
int n; | ||
Nhap(a, n); | ||
int kq = DauTien(a, n); | ||
cout << "Gia tri le dau tien la: " << kq; | ||
return 0; | ||
} | ||
int DauTien(int a[], int n) | ||
{ | ||
if (n == 0) | ||
return 0; | ||
int s = DauTien(a, n - 1); | ||
if (s != 0) | ||
return s; | ||
if (a[n - 1] % 2 != 0) | ||
return a[n - 1]; | ||
return 0; | ||
} | ||
} | ||
|
||
void Nhap(int a[], int& n) | ||
{ | ||
cout << "Nhap n:"; | ||
cin >> n; | ||
cout << "Nhap mang: "; | ||
cout << endl; | ||
for (int i = 0; i < n; i++) | ||
cin >> a[i]; | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,50 @@ | ||
#include <iostream> | ||
#include<iostream> | ||
#include<iomanip> | ||
using namespace std; | ||
int ViTriCuoi(int[], int); | ||
void Nhap(int a[], int& n); | ||
bool ktHoanThien(int); | ||
|
||
int main() | ||
{ | ||
|
||
int a[100]; | ||
int n; | ||
Nhap(a, n); | ||
int kq = ViTriCuoi(a, n); | ||
cout << "Vi tri so hoan thien cuoi cung la: " << kq; | ||
return 0; | ||
} | ||
} | ||
int ViTriCuoi(int a[], int n) | ||
{ | ||
if (n == 0) | ||
return -1; | ||
if (ktHoanThien(a[n - 1])) | ||
return n - 1; | ||
return (ViTriCuoi(a, n - 1)); | ||
} | ||
|
||
void Nhap(int a[], int& n) | ||
{ | ||
cout << "Nhap n:"; | ||
cin >> n; | ||
cout << "Nhap mang: "; | ||
cout << endl; | ||
for (int i = 0; i < n; i++) | ||
cin >> a[i]; | ||
} | ||
|
||
bool ktHoanThien(int a) | ||
{ | ||
int s = 0; | ||
int n = 1; | ||
while (n < a) | ||
{ | ||
if (a % n == 0) | ||
s += n; | ||
n++; | ||
} | ||
if (a == s) | ||
return true; | ||
return false; | ||
} | ||
|