A function called sum that takes n as a parameter and then returns the value of 13+23+33+...+n3.Sample command => output:(display (sum 5)) => 225
for the given example answer shold be 165 not 225.
13+23+33+43+53=165
since no language is mentioned, I used C++
#include<bits/stdc++.h>
using namespace std;
int sum(int n){
int unit_digit=(n*3)%10;
int rest_number=((n*3)/10+n*(n+1)/2)*10;
int ans=unit_digit+rest_number;
return ans;
}
void display(int n){
cout<<n<<endl;
}
int main(){
display(sum(5));
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.