Question

A function called sum that takes n as a parameter and then returns the value of...

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

Homework Answers

Answer #1

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;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
A function called combthat takes twoparameters: n,rand returns the value of n choose r.Sample command =>...
A function called combthat takes twoparameters: n,rand returns the value of n choose r.Sample command => output:(display (comb 6 3))=> 20Hint: The value of n choose r, C(n,r),is recursively defined as:C(n,r) = n, if r =1= 1, if r = n or r = 0= C(n-1,r-1) + C(n-1, r), otherwise program language Scheme
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a Python function that takes a filename as a parameter and returns the string 'rows'...
Write a Python function that takes a filename as a parameter and returns the string 'rows' if a file was written row by row, and 'columns' if the file was written column by column. You would call the function with a command like filetype = myfunc(filename).
Write a function makeDoubles in c++, that takes an integer parameter called size and: allocates a...
Write a function makeDoubles in c++, that takes an integer parameter called size and: allocates a new array of that many double's initializes all elements to be 0 returns this array
Write a function that takes two integer inputs and returns the sum of all even numbers...
Write a function that takes two integer inputs and returns the sum of all even numbers between these inputs, and another function that takes two integer inputs and returns the sum of odd numbers between these inputs .In main function, the program will asks the user to enter two integer numbers and then passes them to these two functions and display the result of each of them.         [0.5 mark] (BY USING C PROGRAM)
Write a function named "replacement" that takes a string as a parameter and returns an identical...
Write a function named "replacement" that takes a string as a parameter and returns an identical string except with every instance of the character "i" replaced with the character "n python
Define a function called ngram_list() that takes a filename and a positive integer n representing the...
Define a function called ngram_list() that takes a filename and a positive integer n representing the number of characters to be displayed on each line (but don't actually display anything in this function — so no print() in this function). The function should return a list of strings, consisting of the contents of the file split into chunks n characters long. If there is an error working with the file, the function should return an empty list. For example, using...
(C++) Write a function called triple that takes an array of integers as a parameter as...
(C++) Write a function called triple that takes an array of integers as a parameter as well as the length of the array. It should triple each value in the array. The function should not return anything. (Note that the contents of the array WILL be modified.)
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT