Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // bai 1
- int n, a[100], tong = 0;
- cout << "Nhap n: "; cin >> n;
- for (int i = 0; i < n; i++) {
- cout << "Nhap a[" << i << "]: "; cin >> a[i];
- }
- cout << "Ket qua: ";
- for (int i = 0; i < n; i++) {
- if (a[i] >= 0 && a[i] <= 10) cout << a[i] << ' ';
- if (a[i] > 10 && a[i] % 2 == 1) tong += a[i];
- }
- cout << endl;
- cout << "Tong le lon hon 10: " << tong << endl;
- // bai 2
- string s; char c; int dem = 0, vt = -1;
- cout << "Nhap s: "; getline(cin, s);
- cout << "Nhap c: "; cin >> c;
- for (int i = 0; i < s.size(); i++) {
- if (s[i] == c) {
- dem++;
- if (vt == -1) vt = i;
- }
- }
- cout << "So ky tu c: " << dem << endl;
- cout << "Vi tri dau tien xuat hien c: " << vt << endl;
Advertisement
Add Comment
Please, Sign In to add comment