-Write a function sumsteps2 that calculates and returns the sum of 1 to n in steps of 2, where n is an argument passed to the function. For example, if 11 is passed, it will return 1 + 3 + 5 +7+9 + 11. Do this using a for loop. Calling the function will look like this: >> sumsteps2 (11) ans =
Q: 5. An integer is said to be prime if it's divisible by onlv 1 and itself. For example, 2, 3, 5 and 7…
A: int isPrime(int n){ for(int i=2;i <= n/2;i++) { if(n%i==0) {…
Q: Exercise 3: Write a function fact (n) which returns the factorial of n (n!). Vote: n! is undefined…
A:
Q: 17: recursion.cpp) Write two recursive integer functions. The first function should calculate…
A: Introduction of the Program: The C++ program takes the number from the user as input and displays…
Q: Define a function in loop_functions.py named count_collatz that takes a single parameter named a_0.…
A: Hailstone Sequence: It is the sequence that calculates the number that may get increased or…
Q: Computer Engineering In multiplication, assume that leading zeroes are not allowed. Write a program…
A: Given: In multiplication, assume that leading zeroes are not allowed. Write a program in C++ to help…
Q: Hello I am having a bit of trouble with this homework question and this is the topic of functions 1…
A: Program: //header files #include <iostream> #include<conio.h> //main body int main() {…
Q: 13- Write a function that takes a positive integer "n" as the function parameter and returns True if…
A: Take a number from user declare a temp variable that is set to False check if the number is greater…
Q: calculte the following formulation. "n" is entered by user. 2x + ("/x) > (1 + 2 x=1 a-Dont use pow…
A: Logic:- define FuncPow taking x as parameter . Iterate from i=1 to i=x cal=cal*2 End…
Q: Design a function that accepts a list of numbers as an argument. The function should recursively…
A: Given: Design a function that accepts a list of numbers as an argument. The function should…
Q: For the following programming problems, you need to time a section of code in C++. For example, the…
A: given:
Q: 1. Write a program uses a Boolean-valued function to determine whether a set of numbers is in a…
A: As per our rules, we should only do the first question in a multi-part question. Please re-submit…
Q: 5.18 (Even or Odd) Write a program that inputs a series of integers and passes them one at a time to…
A: EXPLANATION - Firstly declare variables that are used in program . Then take input from user about…
Q: 4. Write a function called hwd_problemd that computes a sum as defined below. The function returns…
A: Start the program. Perform the operations. Print the outputs. Exit.
Q: Q2: Write a program that input 2 values as a number 'n' and power 'p'. both values must pass to a…
A: Here I have first of all created a function named Power that takes two input as parameters and…
Q: #include using namespace std; bool isThere(string s, char c, int si, int ei){ //return true if…
A: Input : string s char c int si int ei Output : Write the code to check if the character c is…
Q: XOR AX,AX WILL DO THE FOLLOWING FUNCTION
A: Xor gives output 1 if both are same XOR AX,AX ax xor with ax then AX=11111111
Q: 1. Write a function which takes an input 'n' and calculates the sum of the first n natural numbers…
A: The requested Matlab program is provided in the next step by using a for loop and function.
Q: a. Convert the following code segment as follow: -Do while loop → to be converted to → Do Loop Until…
A: Do while is a loop in vb which continue iterating statements as long as condition is true. In case…
Q: REVERSED SUM OF ODD POSITIONS Write a function that takes an integer(n) as input and returns True if…
A: Sample Output Screenshot:
Q: solve in assembley language, MIPS Square Root Calculation: Newton’s iterative method can be used…
A: The answer is given below. #Data section.data #Declare the constantstwo: .double 2.0one: .double…
Q: A palindrome is a string whose first half is equal to the reverse of its second half. - Examples of…
A: Program plan: Define check_palindrome function as follows: Initialize two pointer variables,…
Q: Big sum problem You will implement the big sum arithmetic supported in the calculator (attached…
A: According to Your Requirement, we follow these means to fabricate the declared one integer array…
Q: Rewrite the following code using while loop statement instead of for loop statement in C++.…
A: Rewrite the following code using while loop statement instead of for loop statement in C++.
Q: Program this
A: The Answer is :-
Q: 3- It is not possible to change the value of the pointer. (True or False). 4- If the following lines…
A: We need to answer questions related to C++ program. *As per the guidelines only 1st 3 question is…
Q: 1. Write a program uses a Boolean-valued function to determine whether a set of numbers is in a…
A: import random; #importing random module to generate random numbers def isInRange(x):…
Q: Complete it. #include using namespace std; bool isThere(string s, char c, int si, int ei){…
A: Complete the given C++ program. Basic Information About the given program: In the given program we…
Q: 2- Write a pyhton function that prompts the user to input three integers and prints the sum of those…
A: Given: 2- Write a pyhton function that prompts the user to input three integers and prints the sum…
Q: (Numerical) Write a program that tests the effectiveness of the rand() library function. Start by…
A: Given: Write a program that tests the effectiveness of the rand() library function. Start by…
Q: #include #include #define MAX 4000 int main(void) FILE* bkPtr; char buffer[MAX]; fopen_s(&bkPtr,…
A: Robinson Crusoe is a novel by Daniel Defoe, first published on 25 April 1719. The first edition…
Q: using c++ Write a program that read a word from user. Then, create a function void reverse(char s[])…
A: The C++ program along with the snapshot of code and output is given below.
Q: please code in python Find the Error The following function takes in a positive integer and returns…
A: logic:- In the above function , at first time only if condition fails else condition is returning…
Q: 6) The function returns the value of x def my_func (x, p):
A: Algorithm: The algorithm to return the value of xp is: Start def my_func(x,p): y=x**p…
Q: program
A: Given :- List in python and the programming language used is python Need to write the in_order()…
Q: Let the sequence a, be defined by 1Sa? – 30a, + 25|, n > 0 with ao - 17 +2 v7 An+1 = 5 Write a…
A: We need to define a method that compute the an as per the given formula.
Q: Instructions: In the code editor, you are provided with a function that checks whether a number is…
A: In main method, initialise a variable 'n'. Take n as a user input. Initialise an array of the size…
Q: Write a program that computes the following. Use while loop. Define a function as follows: public…
A: Here I have defined the function addAll(). In this function, I have used a while loop till the value…
Q: how to write a function in python 3 using for loop that counts how many times a consonant (either…
A: Note: The given program is compiled and executed in "repl.it" online compiler.
Q: arguement and returns true if the arguement is a prime number and otherwise returns false. This…
A: Step 1: Here a new python program with name "main.py" is created, which contains following code.
Q: C++ - Rolling a single six-sided die produces a random number between 1 and 6 with a uniform…
A: Actually, array is a collection of elements.
Q: H.W: - Write a program to calculate the following function fx for n that is given by the user. in…
A: Note: since value for z , a, x is not defined so. we assume our own value. you can you use any…
Q: please code in python 1). Multiplication using Addition Write a function: mul(a,b) that will…
A: 1) Below is a program that defines functions for mul(a,b) that will compute and return the…
Q: C++ By using a function and only use #include (other library and ANY LOOP(for, while) are not…
A: By using a function and only #Include (without any loops)
Q: 4. You are given the following functions: int functionA (int a) { printf ("a-td\n", a); if (a--1)…
A: The program is written in C Language. Check the program screenshot for the correct indentation.…
Q: 11.11 LAB: Number pattern Write a recursive function called PrintNumPattern() to output the…
A: Actually, programming is an executable software that runs on a computer.
Q: Write a function prodby2 that will receive a value of a positive integer n and will calculate and…
A: As there is no programming language mentioned so program is attempted in python language start…
Q: In loop functions.py, define a function named permutations that takes two paramters, n and r, in…
A: def permutations(n,r): product=1; #store the value in a variable named…
Q: 2. Modular arithmetic Write a function that returns the result of any integer modulo of n (i.e.,…
A: Actually, function is a group of statements. The given information is: /* precondition: n is greater…
Q: Write code to complete raise_to_power(). Note: This example is for practicing recursion; a…
A: For the Given function, we have to complete the python code that prints the power of the given…
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
- 2- The factorial n! of a positive integer n is defined as n! = 1*2*3 . .. * (n-1) * n Where 0! = 1 Write a function to calculate the factorial of a number. Argument: A number n of type unsigned int. Returns: The factorial n! of type long double. Write two versions of the function, where the factorial is • calculated using a loop calculated recursively Test both functions by outputting the factorials of the numbers 0 to 20.Write code that uses any type of loop. The code should continually ask for a user input and sums all user inputs that are divisible by 2. The loop should continue until the user enters a negative number. The code should output the sum a single time once user entry has completed. You may assume all libraries and namespaces have been previously written into the code, you are just writing everything that would go inside the main function (beyond the return 0:).Boolean Function - Pythona) Define a function, isInRange() with an integer parameter, x. This function returns true if the integer number x is in the range (-100, 100). Otherwise, return false.b) Define a main() function, in which a loop will be created to do the following ten times: - Get a random integer, n, in the range (-500, 500).- Call isInRange(x) function to determine and print out if the number n is in the range.c) Call main() function to initiate the tasks to be performed.
- Programming Language = Python 3. Recursive Lines Write a recursive function that accepts an integer argument, n. The function should display n lines of asterisks on the screen, with the first line showing 1 asterisk, the second line showing 2 asterisks, up to the nth line which shows n asterisks. Sample Output A AA AAA AAAA NOTE: Print A NOT * character as an output for n.C++ Coding: Nested Loops Create a constant DIM. Set DIM to 7, and use a nested loop to display the following square matrix output. Output Example: - - - X - - -- - - X - - -- - - X - - -X X X O X X X- - - X - - -- - - X - - -- - - X - - -use a while loop instead of for loop for this function you are not allowed to use any of the following: dictionaries or dictionary methods try-except break and continue statements recursion map / filter
- Programming Assignment:Here is a loop that starts with an initial estimate of the square root of a, x, and improves it until itstops changing:while True: y = (x + a / x) / 2 if abs(y - x) < epsilon: break x = ywhere epsilon has a value like 0.0000001 that determines how close is close enough.Encapsulate this loop in a function called square_root that takes a as a parameter, chooses areasonable value of x, and returns an estimate of the square root of a.To test the square root algorithm in this chapter, you could compare it with math.sqrt. Write afunction named test_square_root that prints a table like this:1.0 1.0 1.0 0.02.0 1.41421356237 1.41421356237 2.22044604925e-163.0 1.73205080757 1.73205080757 0.04.0 2.0 2.0 0.05.0 2.2360679775 2.2360679775 0.06.0 2.44948974278 2.44948974278 0.07.0 2.64575131106 2.64575131106 0.08.0 2.82842712475 2.82842712475 4.4408920985e-169.0 3.0 3.0 0.0The first column is a number, a; the second column is the square root of a computed with the[your…python nMath: pentagonal numbers) A pentagonal number is defined as n(3n-1)/2 for n=1,2,..., and so on. So, the first few numbers are 1, 5, 12, 22, .... Write a function with the following header that returns a pentagonal number: def getPentagonalNumber(n): Write a test program that uses this function to display the first 100 pentagonal numbers with 10 numbers on each line.main.c + c Test Cases Executions 3. Negative Fusion by CodeChum Admin 1 E Run Tests As l've said before, there are three types of numbers: the positive, the zero, and the negative ones. Today, we shall pay attention only to the negative ones now. Make a loop that will accept O Test Case 1 random decimal/float numbers. When the user Your Output inputs 0, the loop will terminate and then output No Output the sum of all negative numbers inputted in 3 decimal places. Expected Output Let's code this. Enter a number: 2.4434 Enter a number: -1.3433 Input Enter a number: -2.444 Enter a number: 6.432 1. A series of decimal numbers Enter a number: 0 Sum of all negatives = -3.787 Output The first lines will contain message prompts to input the decimal numbers. The last line contains the sum of all negative numbers with 3 decimal places. O Test Case 2
- #include <stdio.h> int main(){ int a; /* for loop execution */ for ( a = 1; a <= 100; a++){ printf("%d\n",a * a); } return 0; } write a code using while loop that will provide the same output as the code given above.C++ Vector iteration: Sum of excess. Vector testGrades contains NUM_VALS test scores. Write a for loop that sets sumExtra to the total extra credit received. Full credit is 100, so anything over 100 is extra credit. Ex: If testGrades = {101, 83, 107, 90}, then sumExtra = 8, because 1 + 0 + 7 + 0 is 8.2. Test Scores File: test_scores.py Write pseudocode for the main() part of a program that asks the user to enter 4 test scores between 0 and 100, then displays a JCU grade for each score and also the average test score. When you have written the pseudocode for main, implement your solution in Python code and test it with a range of meaningful data. Remember that we've done the JCU grades question before, so copy your function from that practical code file. Sample Output Score: 3 Score: 50.5 Score: 66 Score: 100 Score 3.0, which is N Score 50.5, which is P Score 66.0, which is C Score 100.0, which is HD The average score was 54.875 Enhancements When you have that working... We asked for 4 scores. Have a look at your code... did you use 4 as a numeric literal or a constant?Change 4 to 3... Did you have to change the program in more than one place?If so, then you've missed one of the things we've taught...As a strong guideline: if you need to use the same literal more than once, you…