fork download
  1. #include <iostream>
  2. #include <stdlib.h>
  3.  
  4. using namespace std;
  5.  
  6. int main(){
  7. system("cls");
  8. int n, tong,i;
  9.  
  10. cout << "Moi ban nhap vao n: ";
  11. cin >> n;
  12. tong = 0;
  13. // for (int i = 0; i <= n; i++)
  14. // {
  15. // if(i % 2 == 0){
  16. // tong += i;
  17. // }
  18. // }
  19. // cout << "Tong cua day so la: " << tong << endl;
  20. if(i % 2 != 0){
  21. i++;
  22. }
  23. for (int i = 0; i <= n; i += 2)
  24. {
  25. tong += i;
  26. }
  27. cout << "Tong cua so chan: " << tong << endl;
  28. return 0;
  29.  
  30. }
Success #stdin #stdout #stderr 0.01s 5272KB
stdin
Standard input is empty
stdout
Moi ban nhap vao n: Tong cua so chan: 268419072
stderr
sh: 1: cls: not found