Question

11. Write a program to compute the sum of the series 12 + 22 + 32....

11. Write a program to compute the sum of the series 12 + 22 + 32. . . ., such that the sum is doesnot exceed 1000. The program should display how many terms are used in the sum.

{3 marks}

matlab only

1 to power of 2 , 2 to the power of 2 , 3 to the power of 3 , not 12 + 22 + 32

Homework Answers

Answer #1

The MATLAB script to calculate and print the number of terms in the series whose sum is less than 1000 is:

%Declaring a int variable result to store sum of series
result=0;
% Declaring int variable count to keep track of no.of terms
count=0;
% Using while loop to calculate sum of series
% 1^1+2^2+3^3 ... till sum is less than 1000
while result<1000
    % Incrementing count variable every time this loop runs
    count=count+ 1;
    % Calculating sum of series by adding new term to old sum
    result = result + count.^count;
  
end
% Printing output using formatted print statement fprintf()
fprintf("Number of terms used in series : %d",count-1);

Using a while loop I have iterated through the sum of series 1^1+2^2+.... by checking if the sum is less than 1000. If the sum is greater than 1000 then we terminate the loop and print number of terms in the series made the highest sum of the series which is less than 1000.

I have tested the code and validated output. 1^1+2^2+3^3+4^4 results the sum 288. But when next term in the series 5^5 is added the result becomes 3413. So the number of terms in the series that make the highest sum less than 1000 is 4 and the sum is 288. I am sharing output screenshot for your reference.

Hope this answer helps you.

If you find this answer helpful, Please upvote the answer.
Thank you :)

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
write a java code. Write a program using loops to compute the sum of the 30...
write a java code. Write a program using loops to compute the sum of the 30 terms of the series below. 91/(3 + 2 + 2) + 92/(4 - 4 + 5) + 93/(5 + 6 - 8) + 94/(6 - 8 + 11) + 95/(7 + 10 + 14) + 96/(8 - 12 - 17) + . . . . Output: Term Ratio Sum 1 13 13 2 18.4 31.4 etc etc
1- Write algorithm (in pseudo-code) for the following problem: sum of the series: 1 +2+3+…+N 2-...
1- Write algorithm (in pseudo-code) for the following problem: sum of the series: 1 +2+3+…+N 2- Convert an algorithm to a flowchart diagram. 3- Counting the primitive operations of the algorithm. 4- Determine algorithm complexity. 5- Write a complete C++ program for the previous algorithm where the program should contain the following:  Display messages.  Input any number;  Display the series.  Display the sum of the series.
Write a program that asks the user for a number in the range 1 through 12....
Write a program that asks the user for a number in the range 1 through 12. The program should display the corresponding month of the year, where 1 = January, 2 = February, 3 = March, 4 = April, 5 = May, 6 = June, 7 = July, 8 = August, 9 = September, 10 = October, 11 = November, and 12 = December. The program should display an error message if the user enters a number that is outside...
Write a C++ program to read a positive integer greater than 0, the program should compute...
Write a C++ program to read a positive integer greater than 0, the program should compute and display the following: - Sum of odd digits in the number - Count of even digits in the number - The smallest digit.                    For example, if the input is 24536, then Sum of odd digits in the number = 8 Count of even digits in the number = 3 Smallest digit = 2
Python: Write a program that makes sum of 1, 2, 3, … until the sum is...
Python: Write a program that makes sum of 1, 2, 3, … until the sum is over 1000.
1- Write a program to print only the even numbers from 100 to 200 2- Write...
1- Write a program to print only the even numbers from 100 to 200 2- Write a program to print the odd numbers from 22 – 99 3- Write a program to calculate howe many even number from 10 to 120 1- Write a program to find only the even numbers for 12 different numbers 2- Write a program to find the odd numbers for 10 different numbers 3- Write a program to calculate howe many even number and how...
Write a python program to find the sum of the first n natural numbers, where the...
Write a python program to find the sum of the first n natural numbers, where the value of n is provided by the user. What is the sum of the first 200 numbers? Write a program that finds the average of a series of numbers entered by the user. As in the previous problem, the program will first ask the user how many numbers there are. Note: the average should always be a float. What is the average of 10.2,...
Write a Python program to find the sum of the binary numbers in list L, where...
Write a Python program to find the sum of the binary numbers in list L, where the binary numbers do not have the quote marks necessary for the int() function. For example, if L = [101, 11, 1010] then the sum is 5 + 3 + 10 = 18. What is the sum when L is L = [10100, 101000, 100000, 1011111, 1000, 1010111, 1010010, 11001, 101100, 10111, 11011, 1011010, 11101, 10, 110011, 1001111, 110010, 101100, 100001, 111001]
Consider the f-number series 32 22 16 11 8 5.6 4 2.8 2 1.4 1 If...
Consider the f-number series 32 22 16 11 8 5.6 4 2.8 2 1.4 1 If I move from f number = 22 to f number = 8, how much have I changed the amount of light?
Step 1: Write a Java program that finds the sum of 10 numbers entered by the...
Step 1: Write a Java program that finds the sum of 10 numbers entered by the user. Step 2: Modify the previous program so that it asks the user how many numbers they have, inputs that many numbers, and finally outputs the average of their numbers. The messages to the user should be clear throughout.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT