Kat H.

asked • 04/19/21

Squares Adder. Write a program that reads in a number (integer) indicating how many values you are to read.

Write a program that reads in a number (integer) indicating how many values you are to read. Then read in that many more numbers (all integers) and output the sum of their squares.


Input of 4 1 2 3 4 would mean "Read in 4 numbers" - the 1 2 3 and 4. Read each one in and add its square to the total. 1+4+9+16 would mean an output of 30


Hint: Steps to a solution:

  1. First read in the first input (how many more numbers there are and count from 1 to that value. The first test should count to 4, the second test count to 2, the third test count to 6.
  2. Then instead of just counting - try to read in that many inputs and print them back out. Basically print all of the inputs except the first. (First test should print 1 2 3 4, second 5 10, third 2 4 8 16 32 64
  3. Then print each number squared
  4. Now you can worry about summing the squares

Code:


#include <iostream>

using namespace std;


int main()

{

//YOUR_CODE

}


2 Answers By Expert Tutors

By:

Patrick B. answered • 04/20/21

Tutor
4.7 (31)

Math and computer tutor/teacher

Michael L. answered • 04/20/21

Tutor
5 (7)

Google Software Engineer |Duke Computer Science Grad| USAMO/USACO Prep

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.