bai 4

 avatar
canhquydev
plain_text
a year ago
319 B
9
Indexable
#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;
}
Editor is loading...
Leave a Comment