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
blsea [12.9K]
3 years ago
7

X274: Recursion Programming Exercise: Cannonballs Spherical objects, such as cannonballs, can be stacked to form a pyramid with

one cannonball at the top, sitting on top of a square composed of four cannonballs, sitting on top of a square composed of nine cannonballs, and so forth.
RequireD:
Write a recursive function that takes as its argument the height of a pyramid of cannonballs and returns the number of cannonballs it contains.
Computers and Technology
1 answer:
Inga [223]3 years ago
3 0

Answer:

The function in C is as follows:

#include <stdio.h>

int C_ball(int height){

if(height == 1) {

       return 1;}

   return (height * height) + C_ball(height - 1);}      

int main(){

   int n;

   printf("Height: ");

   scanf("%d",&n);

   printf("Balls: %d",C_ball(n));

   return 0;

}

Explanation:

The function begins here

#include <stdio.h>

This defines the function

int C_ball(int height){

If height is 1, return 1

<em>if(height == 1) { </em>

<em>        return 1;}</em>  

This calls the function recursively

   return (height * height) + C_ball(height - 1);}

The main begins here

int main(){

This declares the height as integer

   int n;

This prompts the user for the height

<em>    printf("Height: "); </em>

<em>    scanf("%d",&n);</em>

This calls the function

   printf("Balls: %d",C_ball(n));

   return 0;

}

You might be interested in
Use the drop-down menus to complete statements about archiving and backing up data fileArchiving data files manages the size of
svetoff [14.1K]

Answer:

Archiving data files manages the size of a mailbox for  

✔ local

storage.

Creating an Outlook data file  

✔ protects

data files in storage on a computer.

Explanation:

Because its right.

3 0
3 years ago
Read 2 more answers
What type of network is the internet
shtirl [24]

Answer:

The internet is considered as Wide Area Network (WAN).

5 0
3 years ago
A(n)<br> is a fast compute with lots of storage. pls help
Pachacha [2.7K]

Answer:

Surface Laptop 3 - 15", Platinum (metal), AMD Ryzen 5 3580U, 8GB, 128GB

4 0
3 years ago
Read 2 more answers
If a _____ error appears when you run a macro that has worked in the past, some part of the macro code no longer makes sense to
Burka [1]
If a run-time error appears when you run a macro that has worked in the past, some part of the macro code no longer makes sense to excel, ehere run-time denotes <span> the time during which a program is running</span>
This error occurs while the program is running.
Running<span> out of memorywill results in  a </span>run-time error.
5 0
3 years ago
Carl is a music teacher. He builds custom computer systems for his students to use when they are learning and creating music. Ca
shutvik [7]

Answer:

um ahh <em> </em><em>badl</em><em>y</em><em> </em>

Explanation:

i really don't know the answer

4 0
2 years ago
Other questions:
  • Tornado Alley is located in the middle of the United States, extending from Texas up through the Dakotas. The above statement is
    14·1 answer
  • The part of the computer that contains the brain, or central processing unit, is also known as the A. monitor. B. keyboard. C. m
    13·2 answers
  • • What is the difference between primary storage, secondary storage, and off-line storage
    10·1 answer
  • Which of the following statements about Linux is not​ true? A. Linux works on all the major hardware platforms. B. It plays a ma
    5·1 answer
  • Write an application that inputs a telephone number as a string in the form (555) 555-5555. The application should use String me
    10·1 answer
  • What is it called when you make a reference in the text of a document alerting the reader that you are using information from an
    10·1 answer
  • Which HTML tag is used to add a paragraph to a web page?
    15·1 answer
  • Which 1947 Invention paved the way for the Digital Revolution?
    12·2 answers
  • A company creates a ______by using a wireless access point (WAP) and an Internet connection. Select the two correct answers, the
    11·1 answer
  • Javier downloads an illustration from an online Image library and modifies it for his purposes. The illustration he downloads is
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!