2012-12-26T08:18:12-05:00
Program to find the sum of the series 1+2+3...+n
Program to find the sum of the series 1(pow)+2(pow)+3(pow)...+n(pow)
1
2012-12-26T11:49:13-0500
#include <iostream> #include <conio.h> #include <math.h> using namespace std; long sum_1(int n) { return n * (1 + n) / 2; } long sum_2(int n, int m) { long result = 0; for (n; n > 0; n--) result += (long)pow((long double)n, m); return result; } void main() { int n, m; cout << "Enter n: "; cin >> n; cout << "Enter m: "; cin >> m; cout << "The sum of the 1st series is: " << sum_1(n) << endl; cout << "The sum of the 2nd series is: " << sum_2(n, m) << endl; getch(); }
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS !
Learn more about our help with Assignments:
C++
Comments