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
How to connect tablet to your bluetooth at home?
anygoal [31]
Make sure both devices are enabled or are able to connect via Bluetooth. Set the tablet to "discover" mode. Or, you can have it scan for nearby Bluetooth devices. Select the device. Sometimes, you are prompted for a password or code. If you don't have the manual (which usually states it) you can use either 0000 or 1234. 
5 0
3 years ago
The following statement calls a function named half, which returns a value that is half
nadezda [96]

Answer:

function half(number) {

     let result = number/2;

     return result;

}

Explanation:

4 0
3 years ago
Are the blank space around the edges of the page
Law Incorporation [45]

Answer:

The blank space around the edges of a sheet of paper — as with the page of a book — that surrounds the text is called the margin.

8 0
2 years ago
Which of the following is NOT a name of one of the central features of Facebook? Timeline Activity Log Graph Search Daily News
Thepotemich [5.8K]
I think it's Graph Search because there isn't any graphs in Facebook. That is my opinion. I don't use social media.
4 0
3 years ago
What is it called when the system and all the components except for the real-time clock are powered down
Colt1911 [192]

Answer:

The correct answer to the following question will be "Mechanical off mode".

Explanation:

  • The device will appear to be either on or off to the user. No other states are measurable. The device does, however, support various power states that suit the power states specified in the ACPI specification. Such states also differ, like hybrid sleep and rapid startup. This subject discusses certain states and how they will be represented.
  • The system is completely off, and no power is used. Only after a full reboot will the machine return to working condition.
  • It is called mechanical off mode when the machine and all parts, except for the actual-time clock, are down powered.

Therefore, Mechanical off mode is the right answer.

8 0
3 years ago
Other questions:
  • When forced distribution is used to reduce leniency bias, this can cause __________ if a pfp system is in place?
    10·1 answer
  • You have a user who takes his laptop home every day after work. When he's working in the office, the laptop must get an IP addre
    13·1 answer
  • How many water bottles must be collected to win?
    8·2 answers
  • A server that provides data transfer and storage space at remote locations is called a
    7·1 answer
  • Namecoin is an alternative blockchain technology that is used to implement decentralized version of Routing Banking System.A. Tr
    14·1 answer
  • 50 POINTS &amp; A FOLLOW!
    11·2 answers
  • Renae wants to write a blog about her favorite sports stars. She wants the blog to be informative and visually appealing, so she
    13·2 answers
  • Extended essay on globalization not less than 200​
    6·1 answer
  • ....................................................................................................
    12·1 answer
  • Is it true that if the user log out the computer will turn off automatically​
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!