1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
ozzi
3 years ago
8

Write a function addUpSquaresAndCubes that adds up the squares and adds up the cubes of integers from 1 to N, where N is entered

by the user. This function should return two values - the sum of the squares and the sum of the cubes. Use just one loop that generates the integers and accumulates the sum of squares and the sum of cubes. Then, write two separate functions sumOfSquares and sumOfCubes to calculate and return the sums of the squares and sum of the cubes using the explicit formula below.
Computers and Technology
1 answer:
avanturin [10]3 years ago
7 0

Answer:

All functions were written in python

addUpSquaresAndCubes Function

def addUpSquaresAndCubes(N):

    squares = 0

    cubes = 0

    for i in range(1, N+1):

         squares = squares + i**2

         cubes = cubes + i**3

    return(squares, cubes)

sumOfSquares Function

def sumOfSquares(N):

    squares = 0

    for i in range(1, N+1):

         squares = squares + i**2

    return squares

sumOfCubes Function

def sumOfCubes(N):

    cubes = 0

    for i in range(1, N+1):

         cubes = cubes + i**3

    return cubes

Explanation:

Explaining the addUpSquaresAndCubes Function

This line defines the function

def addUpSquaresAndCubes(N):

The next two lines initializes squares and cubes to 0

    squares = 0

    cubes = 0

The following iteration adds up the squares and cubes from 1 to user input

    for i in range(1, N+1):

         squares = squares + i**2

         cubes = cubes + i**3

This line returns the calculated squares and cubes

    return(squares, cubes)

<em>The functions sumOfSquares and sumOfCubes are extract of the addUpSquaresAndCubes.</em>

<em>Hence, the same explanation (above) applies to both functions</em>

You might be interested in
How should I do it Please code for Java
andrew-mc [135]

Answer:

class Main {  

 public static void printPattern( int count, int... arr) {

     for (int i : arr) {

       for(int j=0; j<count; j++)

           System.out.printf("%d ", i);

       System.out.println();

     }

     System.out.println("------------------");

 }

 public static void main(String args[]) {

   printPattern(4, 1,2,4);

   printPattern(4, 2,3,4);

   printPattern(5, 5,4,3);

 }

}

Explanation:

Above is a compact implementation.

3 0
3 years ago
Columns can be added to a page in the page layout tab in the blank grouping
ZanzabumX [31]

Answer:

Page Setup Grouping.

Explanation:

In Microsoft Word, Columns break up the page into, at max, 13 columns, and at minumum, 2. The way you go about doing this is

  1. Go to the Layout Tab
  2. Go to the Page setup Grouping
  3. Click on the Columns Action
  4. In the Dialog Box, choose either from one of the presents, or custom make your own column settings.
  5. Click Okay
  6. Done!

3 0
3 years ago
Read 2 more answers
What is htc one mseven​
Tamiku [17]

"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"

8 0
2 years ago
Which of the following tabs is used to open, save, and print a document?
liq [111]
File Tab is your answer



Hope this helps.
5 0
3 years ago
Read 2 more answers
Environmental technology examples
meriva

Exhaust Gas Recirculation (EGR) for NOx control
<span>Positive Crankcase Ventilation (PCV) for HC emission control </span>
Evaporative Emissions Control(EVAP)
<span>Catalytic Converter for HC and NOx control</span>
6 0
3 years ago
Other questions:
  • Harold wants to create a design that would depict the innocent and evil sides of human nature. Which colors can Harold use to de
    13·1 answer
  • According to the partnership for 21st-century learning critical thinking ability includes all the following skills except
    15·1 answer
  • How does net neutrality affect consumers actovate in a a positive way?
    8·1 answer
  • How do you run a function in python?
    5·1 answer
  • Give the appropriate term for each of the following.1. An easy-to-remember address for calling a web page (like www.code.org). 2
    8·1 answer
  • 2. Which one of the following is not a feature of technology?
    10·1 answer
  • I need a explanation for this 02 question for a test I will have .
    11·1 answer
  • What is the HTML tag used to define a block of content?<br> O <br> O class<br> O #id<br> O
    8·2 answers
  • 4.(L.5.1.A) Select the sentence that includes an interjection,
    12·1 answer
  • You want to add a caption to a table. which tab contains this option?.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!