Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Sum of series
- // Date : 21.09.19
- #include<bits/stdc++.h>
- using namespace std;
- long long power(int num, int p){
- long long result = 1;
- for(int i = 1; i <= p; i++){
- result *= num;
- }
- return result;
- }
- void series1(int n){
- long long total = 1;
- cout << "The 1st series: \n\n";
- for(int i = 1; i <= n; i++){
- cout << i <<"^2";
- if(i != n) { cout << " X "; }
- total *= power(i, 2);
- }
- cout << " = " << total << endl << endl;
- }
- void series2(int n){
- long long total = 0, num = 3;
- cout << "The 2nd series: \n\n";
- for(int i = 0; i < n; i++){
- cout << num;
- if(i != n-1) cout << " + ";
- total += num;
- num += 3;
- }
- cout << " = " << total << endl << endl;
- }
- void series3(int n){
- long long total = 0;
- cout << "The 3rd series: \n\n";
- for(int i = 1; i <= n; i++){
- cout << i <<"^3 X " << (i+1);
- if(i != n) { cout << " + "; }
- total += (power(i, 3) * (i + 1));
- }
- cout << " = " << total << endl << endl;
- }
- int main(){
- int n;
- cout << "Enter The range of series: "; cin >> n;
- series1(n);
- series2(n);
- series3(n);
- }
Advertisement
Add Comment
Please, Sign In to add comment