Take the sum of squares of 10 different numbers stored in an array.
Question
Take the sum of squares of 10 different numbers stored in an array.
Solution
Sure, here is a step-by-step guide on how to do it:
-
First, you need to have an array of 10 different numbers. Let's assume you already have this array.
-
Initialize a variable to hold the sum of squares. You can name it
sum_of_squaresand initially set it to 0. -
Loop through each number in the array. You can use a for loop for this.
-
In each iteration of the loop, square the current number and add it to
sum_of_squares. You can square a number by multiplying it by itself. -
After the loop ends,
sum_of_squareswill hold the sum of squares of all numbers in the array.
Here is a pseudo-code representation of the steps:
let numbers = [num1, num2, ..., num10]
let sum_of_squares = 0
for each num in numbers do
sum_of_squares = sum_of_squares + (num * num)
end for
print sum_of_squares
This pseudo-code will print the sum of squares of 10 different numbers stored in the numbers array.
Similar Questions
What is the smallest square number, which is the sum of two other square numbers?
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.
A 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.
Which is the smallest number that can be written in two ways as the sum oftwo perfect squares
(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.)
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.