Knowee
Questions
Features
Study Tools

Exercise 1-1: Calculate the sum of square of integers from 1 to 100 using a while loop. Output each integer (from 1 to 100) followed by its sum of squares up to that integer.

Question

Exercise 1-1: Calculate the sum of square of integers from 1 to 100 using a while loop. Output each integer (from 1 to 100) followed by its sum of squares up to that integer.

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a Python solution for the problem:

# Initialize variables
i = 1
sum_of_squares = 0

# While loop from 1 to 100
while i <= 100:
    # Calculate the square of the current integer and add it to the sum
    sum_of_squares += i**2
    
    # Print the current integer and the sum of squares up to that integer
    print(f"Integer: {i}, Sum of Squares: {sum_of_squares}")
    
    # Increment the integer
    i += 1

This script initializes a counter i at 1 and a sum_of_squares at 0. Then it enters a while loop that continues until i is greater than 100. In each iteration of the loop, it squares the current value of i, adds that to sum_of_squares, prints the current integer and the sum of squares up to that integer, and then increments i by 1.

This problem has been solved

Similar Questions

Problem StatementA curious young student named Liam stumbled upon a mathematical problem that computes the sum of the squares of its digits.Help Liam compute the result by writing a program using a do-while loop.Note: This question helps in clearing AMCAT exam.Input format :The input consists of a positive integer n.Output format :The output displays the result representing the sum of the squares of its digits.Refer to the sample outputs for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1 ≤ n ≤ 103Sample test cases :Input 1 :1Output 1 :1Input 2 :1000Output 2 :1Input 3 :55Output 3 :50

(This is from Programming Exercise P4.1 at the end of Chapter 4 of Java for Everyone.) Write program fragments (i.e., you do not need to write complete programs) with loops that compute:The sum of all even numbers between 2 and 100 (inclusive).The sum of all squares between 1 and 100 (inclusive).All powers of 2 from 20 up to 220 (inclusive).The sum of all odd numbers between a and b (inclusive), where a and b are integer variables with a ≤ b.The sum of all digits at odd positions (right-to-left starting at 1 as the right-most digit) of a numeric input. (For example, if the input is 432677, the sum would be 7 + 6 + 3 = 16.)The sum of all digits at odd positions (left-to-right starting at 1 as the left-most digit) of a numeric input. (For example, if the input is 432677, the sum would be 4 + 2 + 7 = 13.)

Write a function that reads a number N (1 to 100) and prints all the perfect squares upto N.

) The sum of squares of two consecutive even integers is 244. Find the numbers.

The sum of the squares of two consecutive numbers is 145. Find them.

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.