bai 4

 avatar
canhquydev
plain_text
2 months ago
319 B
5
Indexable
Never
#include <iostream>
#include <math.h>
using namespace std;
int main(){
    int n, s = 0;
    cout << "Nhap n = ";
    cin >> n;
    for(int i = 1; i <= n; i++){
        if(i % 2 == 0){
            s = s + -i*i;
        }
        else{
            s = s + i*i;
        }
    }
    cout << "S= " << s;
}
Leave a Comment