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.
Python: Write a function called sum_odd that takes two parameters, then calculates and returns the sum...
Python: Write a function called sum_odd that takes two parameters, then calculates and returns the sum of the odd numbers between the two given integers. The sum should include the two given integers, if they are odd. You can assume the arguments will always be positive integers, and the first smaller than or equal to the second. To get full credit on this problem, you must define at least 1 function, use at least 1 loop, and use at least...
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT