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
bogdanovich [222]
3 years ago
5

Implement a recursive program that takes in a number and finds the square of that number through addition. For example if the nu

mber 3 is entered, you would add 3+3+3=9. If 4 is entered you would add 4+4+4+4=16. This program must be implemented using recursion to add the numbers together. mips

Computers and Technology
1 answer:
lubasha [3.4K]3 years ago
3 0

Answer:

def recurSquare(n):

   if n == 0:

       return 0

   return recurSquare(n-1) + n + n-1

print(recurSquare(2))

Explanation:

Programming language used is Python.

The recursive function is defined as  recurSquare(n)

The IF statement checks the argument that is passed to the function to ensure it is not equal to zero.

The function is a recursive function, which means it calls itself.

In the return statement the function calls itself and the argument is reduced by 1.

The function keeps calling itself until n is equal to zero (n == 0) it returns zero and the function stops.

You might be interested in
When doing career research online, you always want to make sure you are viewing a reliable source, what factors about the websit
MrMuchimi

Answer:

You want to consider the expertise of the site, if it is a well-known organization, the date and author of the information presented and the site's look.

Explanation:

The factors about the website that you want to consider to make sure you are viewing a reliable source are:

-Expertise of the site: Check if the websites specializes in information related to careers to make sure they have knowledge about the topic.

-Well-known organization: Validate if the organization that manages the website is well establish and is considered reliable.

-Date and author: Look for the date to make sure the information is up to date and avoid information with anonymous authors.

-Site's look: Consider if the website has a professional appearance as that can show that it could be reliable. However, the other factors have to be taken into account.

5 0
4 years ago
Read 2 more answers
3. Write a program that inputs 4 hexadecimal digits as strings (example 7F), converts the string digits to a long – use strtol(i
never [62]

Answer:

#include <stdio.h>

#include <stdlib.h>

int main()

{

char num1[20],num2[20],num3[20],num4[20];

//Checks where the conversion of string to long stops and is required by strtol

char *ptr;

//Stores the converted number string into long.

long result_num1,result_num2,result_num3,result_num4;

//Prompt to enter all the four hexadecimal numbers.

printf("Enter the first hexadecimal number: ");

scanf("%s",num1);

printf("Enter the second hexadecimal number: ");

scanf("%s",num2);

printf("Enter the third hexadecimal number: ");

scanf("%s",num3);

printf("Enter the fourth hexadecimal number: ");

scanf("%s",num4);

//Converting the hexadecimal numbers into long using strtol() function with base 16 for hexadecimal.

result_num1 = strtol(num1,&ptr,16);

result_num2 = strtol(num2,&ptr,16);

result_num3 = strtol(num3,&ptr,16);

result_num4 = strtol(num4,&ptr,16);

//Casting the long to unsigned chars.

unsigned char numb1 = (unsigned char)result_num1;

unsigned char numb2 = (unsigned char)result_num2;

unsigned char numb3 = (unsigned char)result_num3;

unsigned char numb4 = (unsigned char)result_num4;

//Applying the boolean operation on unsigned chars and storing the resultant value in result.

unsigned char result = ((numb1&numb2)|numb3)^numb4;

//Printing the result in capital hex ("%X" take care of this).

printf("%X",result);

return 0;

}

Code OUTPUT

Enter the first hexadecimal number: 1 Enter the second hexadecimal number:2

Enter the third hexadecimal number: 3 Enter the fourth hexadecimal number: 4 Resultant Value: 7 Process returned o (0×0) execution time : 3.076 s

Press any key to continue

4 0
3 years ago
Which function in spreadsheet software can be used to predict future sales or inventory needs?
melisa1 [442]
create a forecast, Excel creates a new worksheet that contains both a table of the historical and predicted values and a chart that expresses this data. A forecast can help you predict things like future sales, inventory requirements, or consumer trends.
6 0
3 years ago
Read 2 more answers
Filtering is a function of _____.
Levart [38]
The answer is: switches.

Explanation:

Filtering is a function of switches.
3 0
2 years ago
Your IT manager wants you to set up three computers to appear to users as one powerful Windows Server 2016 server. What capabili
Marina86 [1]

Answer:

The answer is "Clustering"

Explanation:

Clustering is a technique, which includes the Microsoft Windows and the coordination with an individual multi-PC's, that is mostly connected to the local area network, as a single platform.

  • It is cheaper than one device.
  • It enables you to greater machine performance and increases usability and reliability, that's why the answer to this question is "Clustering".
4 0
3 years ago
Other questions:
  • Before you take any medicine, _____ to see if it could affect your ability to drive.
    8·2 answers
  • identify three of the many shared ethical standards among businesses that are incorporated in codes of ethics
    6·2 answers
  • In nutanix command-line interface (ncli) commands, each entity has a unique set of actions, but a common action across all entit
    15·1 answer
  • What is the meaning of heart symbol in facebook?
    14·1 answer
  • Which of the following is a correctly named cell?<br> B8<br> BB-8<br> 8-B<br> 8B
    11·1 answer
  • The following are three possible logon scenarios. Explain why option (c) below is preferable in terms of system security. a. Wel
    12·1 answer
  • 3. Output the following:<br>a.<br>21%4​
    12·1 answer
  • Why might a programmer want to define his or her own functions? What are some potential disadvantages? How might new functions m
    10·1 answer
  • A class researching the world’s population would like to include a graph that shows historical changes. They have information fr
    7·1 answer
  • What is the decimal number 86 when written as a
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!