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
The Securities and Exchange Commission (SEC) was created to develop and approve a set of common international accounting rules.
Dennis_Churaev [7]

Answer:  

Idk search it on google chrome

Explanation:

3 0
3 years ago
Differentiate between Scope and Linkage
Lera25 [3.4K]

Answer: The difference between the scope and linkage is as follows:-

  • Scope of the variable is defined as the variable view from different program parts whereas the linkage is described as the link that is made between the variable and the declaration function having the common name.
  • Scope of variable describes about the existing time of the variable in the program whereas linkage is defined for the name of variable present in the program is available at all time .

6 0
3 years ago
Consider the code fragment below (with nested loops). int sum = 0;for (int i = 1; i &lt; 5; i++) for (int j = 1; j &lt;= i; j++)
sammy [17]

Answer:

Option d is the correct answer for the above question.

Explanation:

  • The first loop of the program has a second loop and then the statement. In this scenario, the second loop executes for the value of the first loop and the statement executes for the value of the second loop.
  • The first loop executes 4 times, Then the second loop or inner loop executes n times for the n iteration of the first loop, for example, 1 time for the first iteration of the first loop, 2 times for the second iteration of the first loop and so on.
  • Then the inner loop executes (1+2+3+4) iteration which gives the result 10 iterations.
  • The sum initial value is 0 and the "sum++", increase the value of the sum by 1.
  • So the value of the sum becomes 10 after completing 10 iterations of the inner for loop.
  • Hence the 10 will be the output. So the Option d is the correct answer while the other is not.
3 0
3 years ago
What is astronaut favourite key on keyboard? ​
Dennis_Churaev [7]

Answer:

The space bar is an astronauts favorite key

5 0
3 years ago
Read 2 more answers
The matrix theory is used in the ___ technique
wlad13 [49]

Answer:

The matrix theory is used by hill cipher.

Explanation:

Th technique which uses matrix theory is hill cipher technique.

Hill cipher technique is a polygraphic substitution cipher and it is based on linear algebra.

For encrypting a message in Hill Cipher technique each block of n letters is multiplied by an invertible matrix of nxn and that to against modulus 26 and  for the decryption of the message, every block is multiplied by the inverse of the matrix that was used for encryption.

3 0
3 years ago
Other questions:
  • Describe the indicators and hazards of a metal deck roof fire in an unprotected steel joist warehouse as well as the techniques
    6·1 answer
  • In Microsoft Word, when you highlight existing text you want to replace, you are in what
    11·1 answer
  • A smart refrigerator can use what to detect when you are running low on milk, and then send a reminder to you on a wireless.
    8·1 answer
  • Write a program using nested loop to produce the following output:
    6·1 answer
  • Many people keep time using a 24 hour clock (11 is 11am and 23 is 11pm, 0 is midnight). If it is currently 13 and you set your a
    10·1 answer
  • Find the smallest value of n such that LCM of n is 15 is 45​
    5·1 answer
  • You are to calculate the property tax for tax payers. You will ask the county tax clerk if they want to run the program and init
    9·1 answer
  • What model involves the creation of data and process models during the development of an application
    14·1 answer
  • Compare mini and mainframe computer in terms of speed,memory and storage​
    15·1 answer
  • 1. If we want define style for an unique element, then which css selector will
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!