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.Last 3 lines of output:...99 328350100 338350n_sum = 338350 when n = 100
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.Last 3 lines of output:...99 328350100 338350n_sum = 338350 when n = 100
Solution
Here is a Python solution for the problem:
n = 1
sum_of_squares = 0
while n <= 100:
sum_of_squares += n**2
print(f"{n} {sum_of_squares}")
n += 1
This script initializes n to 1 and sum_of_squares to 0. Then it enters a while loop that continues until n is greater than 100. In each iteration of the loop, it adds the square of n to sum_of_squares, prints n and sum_of_squares, and then increments n by 1.
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
Write a function that reads a number N (1 to 100) and prints all the perfect squares upto N.
(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.)
) The sum of squares of two consecutive even integers is 244. Find the numbers.
Problem StatementMisha wants to check and print whether the given number N is a neon number or not. Write a program that uses a function and helps her to complete this task.A neon number is a number where the sum of digits of the square of the number is equal to the number. Function Specifications: int neon(int n)Example 1Input:9Output:9 is a neon numberExplanation:92 = 81, and the sum of its digits (8+1) is equal to the original number (9).Example 2Input:12Output:12 is not a neon numberExplanation:(12)2=144, and the sum of its digits (1+4+4) is not equal to the original number (12).Note: This question helps in clearing technical coding tests for companies like Capgemini.Input format :The input consists of an integer, N.Output format :If N is a neon number, print "[N] is a neon number"Otherwise, print "[N] is not a neon number"
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.