0
Please help me to solve this problem 😭Program to compute the Sum of squares & Sum of powers from 1 to n
8 odpowiedzi
+ 3
Your code works as expected Agel
What help is needed then?
+ 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;
}
+ 1
And better if you put example in your question too
+ 1
ipang i need other code😭,
+ 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 ...
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
0
Is this code from a cpo course, coz then the output reqment might be different? just tell what output is expected.
0
You can use directly
(n(n+1)(2*n+1))/6 for sum of square