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]
2 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]2 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
A _____________ is designed for a individual user.
pishuonlain [190]

Answer:

i don't know it sorry

Explanation:

7 0
3 years ago
Is Flip book drawings, frame by frame (need great drawing skills).
lyudmila [28]
I would say traditional animation
7 0
3 years ago
"The number of hardware chips needed for multiple digit display can be minimized by using the technique called ________"
Dafna1 [17]

Answer: Multiplexing

Explanation:

By using the multiplexing technique we can easily use the multiple digit display in the input pins of the hardware. We can use this technique to display the several digits and the extra hardware is require which is proportional to the number of several digit to be display.

As, hardware use only limited number of input and output pins. Therefore, multiplexing is the technique used the number of hardware chips need for multiple digit display and can be minimize using this technique.

 

4 0
3 years ago
The home keys on the numeric keypad are?
Eva8 [605]
4, 5 , 6 , and plus key
456+
5 0
2 years ago
Read 2 more answers
How do I make sure I have full access to this app where do I put in payment information
marissa [1.9K]

Answer:

click on your profile and im pretty sure it says privacy information and click on that and from there it will ask you for your information

Explanation:

6 0
2 years ago
Other questions:
  • A range in which a measuring instrument or controller does not respond is the
    12·1 answer
  • 4. How can you select non-adjacent cells (i.e. cells that are not all together in one block)?
    5·2 answers
  • Help me on this question
    14·1 answer
  • Web and mobile applications are created for users to only read information. True False
    15·2 answers
  • What is the term used to describe a computer system that can store literary documents, link them according to logical relationsh
    5·1 answer
  • Anyone down to play gta later i play on ps4?
    15·2 answers
  • You have this code in your program.
    7·1 answer
  • Which conditions make using an array a better choice than a list? Select 3 options.
    12·2 answers
  • Discuss the advantages of using analogue multi-tester or digital multi-tester over the other.​
    12·1 answer
  • __________ is a Microsoft software development tool that developers can use to write multimedia applications
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!