tuki2501

a

Mar 22nd, 2021
883
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. // bai 1
  2. int n, a[100], tong = 0;
  3. cout << "Nhap n: "; cin >> n;
  4. for (int i = 0; i < n; i++) {
  5.   cout << "Nhap a[" << i << "]: "; cin >> a[i];
  6. }
  7. cout << "Ket qua: ";
  8. for (int i = 0; i < n; i++) {
  9.   if (a[i] >= 0 && a[i] <= 10) cout << a[i] << ' ';
  10.   if (a[i] > 10 && a[i] % 2 == 1) tong += a[i];
  11. }
  12. cout << endl;
  13. cout << "Tong le lon hon 10: " << tong << endl;
  14.  
  15. // bai 2
  16. string s; char c; int dem = 0, vt = -1;
  17. cout << "Nhap s: "; getline(cin, s);
  18. cout << "Nhap c: "; cin >> c;
  19. for (int i = 0; i < s.size(); i++) {
  20.   if (s[i] == c) {
  21.     dem++;
  22.     if (vt == -1) vt = i;
  23.   }
  24. }
  25. cout << "So ky tu c: " << dem << endl;
  26. cout << "Vi tri dau tien xuat hien c: " << vt << endl;
Advertisement
Add Comment
Please, Sign In to add comment