Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://www.facebook.com/CungHocLapTrinhUIT/
- #include <iostream>
- using namespace std;
- void NhapMang(int a[], int &n)
- {
- do
- {
- cout << "Nhap gia tri n: n > 5 va n < 100";
- cin >> n;
- } while (n <= 5 || n >= 100);
- for (int i = 0; i < n; i++)
- {
- cout << "Nhap a[" << i << "]: ";
- cin >> a[i];
- }
- }
- int Del(int a[], int &n, int k)
- {
- if (k < 0 || k >= n)
- return 0;
- for (int i = k; i < n - 1; i++)
- {
- a[i] = a[i + 1];
- }
- n = n - 1;
- return 1;
- }
- int SNT(int n)
- {
- if (n < 2) return 0;
- int temp = sqrt(n);
- for (int i = 2; i <= temp; i++)
- if (n % i == 0) return 0;
- return 1;
- }
- void InSNT(int a[], int n)
- {
- int sum = 0;
- for (int i = 0; i < n; i++)
- if (SNT(a[i]) == 1)
- {
- cout << a[i] << "\t";
- sum = sum + a[i];
- }
- cout << endl << sum << endl;
- }
- int KTDX(int a[], int n)
- {
- int temp = n / 2;
- for (int i = 0; i < temp; i++)
- {
- if (a[i] != a[n - 1 - i]) return 0;
- }
- return 1;
- }
- //đổi lại thành main để chạy câu đầu trong bài
- void main1()
- {
- int a[100];
- int n;
- NhapMang(a, n);
- Del(a, n, 2);
- InSNT(a, n);
- cout << KTDX(a, n) << endl;
- }
- struct SinhVien
- {
- char MSSV[100];
- char HoTen[100];
- int NamSinh;
- float DTB;
- };
- //tim ve chi so cua thang co diem cao nhat
- int TimMax(SinhVien sv[], int n)
- {
- if (n <= 0) return -1;
- int max = 0;
- for (int i = 1; i < n; i++)
- {
- if (sv[i].DTB > sv[max].DTB)
- max = i;
- }
- return max;
- }
- void InLT5(SinhVien sv[], int n)
- {
- for (int i = 0; i < n; i++)
- {
- if (sv[i].DTB < 5.0)
- {
- cout << sv[i].HoTen << endl;
- cout << sv[i].MSSV << endl;
- cout << sv[i].NamSinh << endl;
- cout << sv[i].DTB << endl;
- }
- }
- }
- //nhap. truoc khi nhap 1 chuoi, fflush(stdin);
- void cap_phat_bo_nho(int *&a)
- {
- a = new int[5];
- for (int i = 0; i<5; i++)a[i] = i + 1;
- }
- void main()
- {
- int n = 5;
- int *a = &n;
- cap_phat_bo_nho(a);
- printf("Gia tri a[0] = %d va n = %d", a[0], n);
- }
Add Comment
Please, Sign In to add comment