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

Commit

Permalink
122 127 completed
Browse files Browse the repository at this point in the history
  • Loading branch information
truonghoangkhiem committed Nov 15, 2023
1 parent 17557c7 commit 7132877
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 6 deletions.
35 changes: 32 additions & 3 deletions Bai122/Source.cpp
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];
}

48 changes: 45 additions & 3 deletions Bai127/Source.cpp
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;
}

0 comments on commit 7132877

Please sign in to comment.