Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int n, i, suma=0, p;
- cout<<"Acesst program calculeaza suma de tipul:1^2-2^2+4^2-4^2+...+(-1)^(n+1)n^2"<<endl;
- cout<<"Introduceti n=";
- cin>>n;
- for(i=1; i<=n; i++)
- { if(i%2==0)
- p=i*(-i);
- else
- p=i*i;
- suma=suma+p;
- }
- cout<<"Suma este:"<<suma;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement