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
In a proper webpage, which tag holds all of a webpages visble HTML
Furkat [3]
If I remember correctly, I believe it's <body></body>
6 0
3 years ago
Read 2 more answers
Internal memory is synonymous with which memory
soldi70 [24.7K]

Answer:

Main Memory (RAM)

Explanation:

This is the memory which is directly accessible to the CPU. It can be called Main Memory, Prime Memory or simply 'Memory'

5 0
3 years ago
Read 2 more answers
What is a symbol such as a heavy dot or another character that precedes a text in a power point
Fantom [35]

Answer:

<em>I </em><em>think </em><em>the </em><em>answer </em><em>is </em><em>a </em><em>bullet.</em>

<em>Hope </em><em>this </em><em>helps</em>

4 0
1 year ago
An online retailer has developed an algorithm to provide personalized recommendations to shoppers. Which form of IPR protects th
Helen [10]

Answer:

should be B.

Explanation:

If not then Im sorry

5 0
2 years ago
Suppose you have a string matching algorithm that can take in (linear)strings S and T and determine if S is a substring (contigu
Zielflug [23.3K]

Answer:

no seishsssssssssssssssssssss

8 0
3 years ago
Read 2 more answers
Other questions:
  • An effectively distributed resume will get an interview
    12·2 answers
  • Which is true about POP3 and IMAP for incoming email?
    6·1 answer
  • Where does most of the work in creating a presentation will take place? Either formatting toolbar, normal (Slide) view, slide so
    12·2 answers
  • Write a Java application that inputs a series of 10 integers and determines and prints the largest and smallest integer. Use a c
    12·1 answer
  • Dana downloads music into her computers random access memory, or ram, without authorization. this is?
    15·1 answer
  • When examining the digital evidence, what stage deals with using keyword searches and file-carving utilities to locate data that
    5·1 answer
  • Which of the following is NOT considered a step in the problem solving process. A Try B Discover C Prepare D Define
    12·1 answer
  • How to make a project using PID and thermacouple
    11·1 answer
  • Select the correct answer from the drop-down menu.
    15·2 answers
  • The computer scientists Richard Conway and David Gries once wrote: The absence of error messages during translation of a compute
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!