-
Notifications
You must be signed in to change notification settings - Fork 2
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
b684209
commit 3f26d09
Showing
6 changed files
with
224 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
int n; | ||
float a[1000]; | ||
cout << "Nhap so phan tu cua day: "; | ||
cin >> n; | ||
for (int i=0;i<n;i++){ | ||
cout << "Nhap phan thu thu " << i+1 << ": "; | ||
cin >> a[i]; | ||
} | ||
float min=a[0],max=a[0]; | ||
for (int i=1;i<n;i++){ | ||
if (a[i]>max) max=a[i]; | ||
if (a[i]<min) min=a[i]; | ||
} | ||
cout << "Phan tu nho nhat trong day la " << min << " va phan tu lon nhat trong day la " << max << "\n"; | ||
return 0; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
int n; | ||
cout << "Nhap vao so phan tu cua mang: "; | ||
cin >> n; | ||
int a[n]; | ||
for (int i=0;i<n;i++){ | ||
cout << "Nhap phan thu thu " << i+1 << ": "; | ||
cin >> a[i]; | ||
} | ||
for (int j=n-1;j>=1;j--){ | ||
for (int i=0;i<=j-1;i++){ | ||
if (a[i]>a[i+1]){ | ||
int tg=a[i]; | ||
a[i]=a[i+1]; | ||
a[i+1]=tg; | ||
} | ||
} | ||
} | ||
cout << "Mang sau khi da sap xep tang dan la: \n"; | ||
for (int i=0;i<n;i++){ | ||
cout << a[i] << " "; | ||
} | ||
cout << "\n"; | ||
return 0; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
int n; | ||
cout << "Nhap so chieu cua vector: "; | ||
cin >> n; | ||
int x[n],y[n]; | ||
for (int i=0;i<n;i++){ | ||
cout << "Nhap x[" << i+1 << "]: "; | ||
cin >> x[i]; | ||
} | ||
for (int i=0;i<n;i++){ | ||
cout << "Nhap y[" << i+1 << "]: "; | ||
cin >> y[i]; | ||
} | ||
int ans=0; | ||
for (int i=0;i<n;i++){ | ||
ans+=x[i]*y[i]; | ||
} | ||
cout << "Tich vo huong cua hai vector x va y la " << ans << "\n"; | ||
return 0; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
int n; | ||
cout << "Nhap vao so phan tu cua mang: "; | ||
cin >> n; | ||
int a[n]; | ||
for (int i=0;i<n;i++){ | ||
cout << "Nhap phan thu thu " << i+1 << ": "; | ||
cin >> a[i]; | ||
} | ||
float min=a[0],max=a[0]; | ||
for (int i=1;i<n;i++){ | ||
if (a[i]>max) max=a[i]; | ||
if (a[i]<min) min=a[i]; | ||
} | ||
for (int i=0;i<n;i++){ | ||
if (a[i]==min){ | ||
a[i]=9999; | ||
} | ||
if (a[i]==max){ | ||
a[i]=-9999; | ||
} | ||
} | ||
for (int j=n-1;j>=1;j--){ | ||
for (int i=0;i<=j-1;i++){ | ||
if (a[i]>a[i+1]){ | ||
int tg=a[i]; | ||
a[i]=a[i+1]; | ||
a[i+1]=tg; | ||
} | ||
} | ||
} | ||
for (int i=0;i<n;i++){ | ||
if (a[i]==9999){ | ||
a[i]=min; | ||
} | ||
if (a[i]==-9999){ | ||
a[i]=max; | ||
} | ||
} | ||
cout << "Mang sau khi sap xep theo yeu cau cua de bai la: \n"; | ||
for (int i=0;i<n;i++){ | ||
cout << a[i] << " "; | ||
} | ||
cout << "\n"; | ||
return 0; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
bool tang(int a[],int n){ | ||
for (int i=0;i<=n-2;i++){ | ||
if (a[i]>a[i+1]){ | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
bool giam(int a[],int n){ | ||
for (int i=0;i<=n-2;i++){ | ||
if (a[i]<a[i+1]){ | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
bool tangngat(int a[],int n){ | ||
for (int i=0;i<=n-2;i++){ | ||
if (a[i]>=a[i+1]){ | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
bool giamngat(int a[],int n){ | ||
for (int i=0;i<=n-2;i++){ | ||
if (a[i]<=a[i+1]){ | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
int main(){ | ||
int n; | ||
cout << "Nhap vao so phan tu cua mang: "; | ||
cin >> n; | ||
int a[n]; | ||
for (int i=0;i<n;i++){ | ||
cout << "Nhap phan thu thu " << i+1 << ": "; | ||
cin >> a[i]; | ||
} | ||
if (tangngat(a,n)==true){ | ||
cout << "Day so tren tang ngat.\n"; | ||
return 0; | ||
} | ||
else if (tang(a,n)==true){ | ||
cout << "Day so tren tang.\n"; | ||
return 0; | ||
} | ||
|
||
if (giamngat(a,n)==true){ | ||
cout << "Day so tren giam ngat.\n"; | ||
return 0; | ||
} | ||
else if (giam(a,n)==true){ | ||
cout << "Day so tren giam.\n"; | ||
return 0; | ||
} | ||
else{ | ||
cout << "Day so tren chua duoc sap.\n"; | ||
return 0; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <iostream> | ||
#include <math.h> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
int n; | ||
cout << "Nhap so chieu cua vector: "; | ||
cin >> n; | ||
int x[n]; | ||
for (int i=0;i<n;i++){ | ||
cout << "Nhap x[" << i+1 << "]: "; | ||
cin >> x[i]; | ||
} | ||
|
||
float c1=0,c2=0,c0=0,cinf=-99999; | ||
for (int i=0;i<n;i++){ | ||
c1+=abs(x[i]); | ||
c2+=x[i]*x[i]; | ||
if (x[i]!=0) c0++; | ||
if (x[i]>cinf) cinf=x[i]; | ||
} | ||
c2=sqrt(c2); | ||
cout << "Chuan 1 cua X la " << c1 << "\n"; | ||
cout << "Chuan 2 cua X la " << c2 << "\n"; | ||
cout << "Chuan vo cung cua X la " << cinf << "\n"; | ||
cout << "Chuan 0 cua X la " << c0 << "\n"; | ||
return 0; | ||
} |