tuki2501

b

Mar 22nd, 2021
1,045
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. // bai 1
  2. int n, a[100], dem = 0, 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. for (int i = 0; i < n; i++) {
  8.   if (a[i] % 2 == 1) dem++;
  9.   if (a[i] >= -20 && a[i] <= 50) tong += a[i];
  10. }
  11. cout << "So luong so le: " << dem << endl;
  12. cout << "Tong trong khoang [-20, 50]: " << tong << endl;
  13.  
  14. // bai 2
  15. string s; int dem = 0;
  16. cout << "Nhap s: "; getline(cin, s);
  17. for (int i = 0; i < s.size(); i++) {
  18.   if (isupper(s[i])) dem++;
  19.   s[i] = toupper(s[i]);
  20. }
  21. cout << "So ky tu in hoa: " << dem << endl;
  22. cout << "Xau s sau khi chuyen: " << s << endl;
Advertisement
Add Comment
Please, Sign In to add comment