0

Please help me to solve this problem 😭Program to compute the Sum of squares & Sum of powers from 1 to n

9th Feb 2021, 5:24 AM
Agel
Agel - avatar
8 ответов
+ 3
Your code works as expected Agel What help is needed then?
9th Feb 2021, 6:38 AM
Ipang
+ 2
this the example of program on that question //Program to compute the Sum of squares & Sum of powers from 1 to N #include <iostream> #include<cmath> using namespace std; int sum_squares (int num); int sum_powers (int num); int main () { int n; cout<<"Enter a number: "; cin>>n; cout<<"The sum of squares from 1 to "<<n<< " is = "<<sum_squares(n); cout<<"\n"; cout<<"The sum of powers from 1 to " <<n<< " is = "<<sum_powers(n); } int sum_squares (int num) { int ssq, i; ssq=0; for (i=1;i<=num;i++) { ssq+=(i*i); } return ssq; } int sum_powers (int num) { int ssp, i; ssp=0; for (i=1;i<=num;i++) { ssp+=pow(i, i); } return ssp; }
9th Feb 2021, 5:54 AM
Agel
Agel - avatar
+ 1
And better if you put example in your question too
9th Feb 2021, 5:38 AM
Atul [Inactive]
+ 1
ipang i need other code😭,
9th Feb 2021, 6:56 AM
Agel
Agel - avatar
+ 1
Ok, so can you describe how that "other code" should look like? As I see it, it is function oriented, as you mentioned in comment. I don't see nothing wrong, I don't get why you want that "other code" anyway ...
9th Feb 2021, 6:59 AM
Ipang
0
Create a function-oriented program that will compute the sum of the squares from 1 to N and sum of the powers from 1 to N this is the question
9th Feb 2021, 5:53 AM
Agel
Agel - avatar
0
Is this code from a cpo course, coz then the output reqment might be different? just tell what output is expected.
10th Feb 2021, 5:21 AM
Sahil Mandavkar
Sahil Mandavkar - avatar
0
You can use directly (n(n+1)(2*n+1))/6 for sum of square
10th Feb 2021, 4:02 PM
Abdullah Said
Abdullah Said - avatar