3. Write a C++ program that implements the following three algorithms and times for various values of n. The program should display a table of the run times of each algorithm for various values of n. //Algorithm A sum = 0; for (i = 1 to n) //Algorithm B sum = 0; for(i = 1 to n) { for (j = 1 to i) //Algorithm C sum = n * (n + 1) / 2 sum = sum + 1 sum = sum + i
Q: 1. Write an algorithm and a C program that gets two numbers from the user and print its…
A: Multiple questions are asked so we will give the answer to the first question only. Please upload…
Q: There are n persons each have 25 paise coins, 50 paise coins and Rs1 coins in the ratio p:q:r but…
A: The ask is to write a C program to find and print no. of 25 paise coins, 50 paise coins and 1 Rs…
Q: 21. Write a c++ program Write an algorithm that inputs a number n and outputs n! (Hint: N! =…
A: Algorithm: start declare n,fact=1 ,i=1 as integer read n check if (n is less than 0) go to step 5…
Q: 3. Write a program in c language to print following pattern for a given n. For n = 4, pattern is: 1…
A: Program Approach: Declare variables i, j and k to use in for loop and rows to store user input Ask…
Q: Write a program in C to check whether two given strings are such that one is a reverse of the other.…
A: Include header file <stdio.h> for standard input output. Include header file <string.h>…
Q: Write a c++ program. Write an algorithm that inputs number n and outputs n! а
A: Algorithm of this program is very easy − START Step 1 → Take integer variable A Step 2 →…
Q: 1. Write a program in C to print first 50 natural numbers using recursion. Expected Output : The…
A: Here we need to use recursion. That is function should call itself until the condition n>50 is…
Q: For the following problem please write an algorithm in plain English .i.e give details as to how you…
A: Algorithm to arrange the deck of 52 cards for the given scenario is as follows:
Q: The time complexity of the following pseudocode is O(n^2). In C++, confirm the time complexity by…
A: Here we have 2 while loops. First while loop will run n times. second while loop will run whenever…
Q: Write a program In C language to print following pattern for a given n. For n = 4, pattern is: * * *…
A: The patterns using star(*) can be printed using loop if/else or recursive function. The loop…
Q: d) Write a program to compute the sum of natural numbers from 101 to 200 in constant time…
A: Write a Python program to compute the sum of numbers from 101 to 200 in constant time complexity.
Q: The factorial function n! has value 1 when n 1 and value n*(n-1)! When n>1. Write both a recursive…
A: function recursive_factorial( n ): Start if n >= 1 then return n * recursive_factorial(n - 1)…
Q: Write a program in C to implement the sequential search algorithm of Chapter 3, Figure 3.1, except…
A: Declare integer variables to hold the number of elements to be entered, user inputted element and…
Q: Write a simple code (python). Given a list of n elments with each element between 1 and n. determine…
A: the python code is l = [int(x) for x in input().split()] s = set(l)if len(s) == len(l): print("no…
Q: Consider the letters X and O lined up one after the other as follows. X O X O X O X O X O Develop…
A: Algorithm: Start Initialize character array 'a' with given data Iterate through the loop from i=0…
Q: these two codes and then answer these questions please: 1) Empirically, show the performance curve…
A: It is defined as a general purpose, case-sensitive, free-form programming language that supports…
Q: What is the time complexity of following code. Show the time complexity of each statement below and…
A: Language is one of the most widely used programming language which has been used to create different…
Q: In C++: given the following recursive definition f(1) = f(2) = 2 f(n) = 2* f(n-1) + f(n-2) write…
A: Program:#include <iostream>using namespace std; int f(int n){ if ((n == 1) || (n == 2))…
Q: 4. Write a C++ program to read input a string from the user and check whether the string is sorted…
A: Algorithm: Start Read number of test cases t Iterate through the lop till t is 0 Read a string…
Q: Write a C++ program that calculate and write out the nth Fibonacci numbers pre
A: Write a C++ program that calculate and write out the nth Fibonacci numbers presented in a table…
Q: Write a dynamic programming algorithm to calculate the following recursive function. 3-8 exp(n)= 8,…
A: The complete is below using pseudo code in Dynamic programming.
Q: 5. a) Run the algorithm below for the input list 5, 9, 10 and complete the table, showing how the…
A: a. Procedure Final(5,9,10) s:=0 k:=1,n=3 WHILE 1<=3 s:=0+5=5 k:=1+1=2 now WHILE 2<=3…
Q: Given a string str and number n, write a program in Javascript that recursively appends a copy of…
A: Here is Your Code function RecursiveCopy(str, n) {if (n === 0) {return "";} else {return…
Q: a) Run the algorithm below for the input list 4, 5, 11 and complete the table, showing how the…
A: Here, we increment value of k each time the loop is run. Since n=3, and loop runs until k<=3, the…
Q: Q1) Write a program in C+ + language to find the result of executing the sequence of iteration…
A: Algorithm Start Variable sum=0, i=2 While(i<=10) go to step 4 else go to step 6 sum=2*i/i+sum…
Q: a. Briefly explain why it is necessary to write an algorithm before writing a program. b. Write an…
A: (A) It is necessary to write algo of the program because in algo we used to write the steps of our…
Q: Solve the problem in C++ (Count occurrence of numbers) Write a program that reads at most 100…
A: Introduction Solve the problem in C++ (Count occurrence of numbers) Write a program that reads at…
Q: 4. Write a pseudocode for the following: a) An algorithm that takes n integers and defines if number…
A: I give the code in Python along with output and code screenshot
Q: f (n) \ 1 logn 1 second 2^ 1 day 1 minute 1 hour 1 month nlogn 2" n!
A: Answer: I have done code and also I have attached code as well as output.
Q: Write a program in C++ to display the below pattern with n rows, where n is in the range between 1…
A: Code: #include <iostream> using namespace std; int main() { int i,j,k; int n;…
Q: Consider the following procedures. PROCEDURE math (ans1, ans2) { a ← INPUT() b ← INPUT() c ←…
A: WORKING: When math is called with values 1 and 2, then ans1 = 1 and ans2 = 2 and user enters a = 3…
Q: Write C++ program that utilize looping and the escape sequence \f to print the following table of…
A: C++ program to print above table : #include<iostream> using namespace std; int main() {…
Q: Write a C++ program using recursive function that ask for a number K then the recursive function…
A: Answer in step2
Q: write a recursive c program that takes as an input a total of N integers and prints every subtotal…
A: write a recursive c program that takes as an input a total of N integers and prints every subtotal…
Q: Write a C program with O (1) complexity that prints the f (n) value shown in the table below against…
A: 1.First initialize all the variables.2. initialize the array as given function f(n).3. take…
Q: Example 1: Write a program to read student name and 6 degree then compute and print the average of…
A: 1. DIM D,X LET X=2 LET D=LOG(X) * LOG(X^2) PRINT "THE RESULT: ";D
Q: Write a recursive C program to read input two integers x,y and print the number x in the output y…
A: Write a recursive C program to read input two integers x,y and print the number x in the output y…
Q: Write a C++ program to do the following: - 1) Define a recursive function that displays the…
A: Since you have asked multiple questions, we will solve the first two questions for you. If you want…
Q: Write the LC3 subroutine to divide X by 2 and print out the remainder recursively(branch for 1 and…
A: .ORIG x3000 LEA R0, REM LD R1, X ADD R2, R0, #-1 BRz DONE BRp NEXT AND R3, R1, #1 STR R3, R0, #0…
Q: (a) Devise a recursive algorithm using design by induction for computing n2 where the input to the…
A: A recursive algorithm for computingwhere n is a non-negative integer is as follow: procedure square…
Q: 8. Programming and experiments (Ex.8.2-7) Please write a general program to solve the all-pairs…
A: The question is to write the code for solving the all pair shortest problem for the digraph. Here C…
Q: a. Write a C program to check whether a given number is divisible by 2, 3, 5, 7 or 11. b. Write a C…
A: a. Write a C program to check whether a given number is divisible by 2, 3, 5, 7 or 11. b. Write a C…
Q: 2.7 For each of the following six program fragments: a. Give an analysis of the running time (Big-Oh…
A: Given code is (1) sum = 0;for( i = 0; i < n; ++i )++sum;(2) sum = 0;for( i = 0; i < n; ++i…
Q: Write a java program that uses a recursive algorithm to print all the valid (properly closed and…
A: import java.util.*; class Paranthesis{ // Function that print all combinations of // balanced…
Q: Write a complete C program to recursively find the largest element of a given array. Input Enter the…
A: Below is the required program in C language. Program Approach: Include necessary header files to…
Q: The factorial of a number n is n! = n(n-1)(n-2)... (n(n-2))1. For instance, the factorial of 5 is:…
A: Coded using C language.
Q: Write a program in C++ to find the area of any triangle using Heron's Formula: Side = (a+b+c)/2…
A: INTRODUCTION: The C++ program given below is used to find the area of any triangle using Heron's…
Q: Consider the following pseudocode of algorithm. Input: number n and list L Steps: a. Read the input…
A: In the above problem, we need to find answers for given questions. Input: number n and list L
Q: 4. Consider the following C program segment. Rewrite it using no gotos or breaks. j - -3; for (i =…
A: Given code:- j = -3; for (i = 0; i < 3; i++) { switch (j + 2) { case 3: case 2: j--; break; case…
Q: Write a program in C+ to do the following tasks. ) Read a number N from the user. ) Using recursion…
A: Program Approach: Including a necessary header file Declaring recursive function to print number…
Step by step
Solved in 2 steps with 3 images
- (C Language) Write a recursive function called PrintNumPattern() to output the following number pattern. Given a positive integer as input (Ex: 12), subtract another positive integer (Ex: 3) continually until a negative value is reached, and then continually add the second integer until the first integer is again reached. For this lab, do not end output with a newline.Write a C++ program where the user inputs two positive integers, A and B, where 5≤ A ≤10 and 20≤ B ≤30. (use user defined functions) A function to output AB (where A is multiplied by itself B times) do not use the built in “pow” function, use your own function. A function that returns the area of a rectangle of height A and width B. A function that returns the sum of odd numbers between A and B. A function to calculate AB recursively. Knowing that AB = AB-1 * A with base case A0 =1Write an algorithm and C program for the following programdefinition: Calculate the weekly gross pay for a series of casual workers, using thefollowing information:a) For each worker there is a line of data with the following fields, separated byblanks - employee number (integer), number of shifts (integer), base wage rate(real) and one real number per shift, representing the number of hours worked.b) Your program should process as many data lines as there are present.c) Gross pay is total hours × base wage rate if the total hours are less than orequal to 15. If the total hours are greater than 15, but less than or equal to 25 thereis a 5% premium on base wage rate (for all hours worked). If the total hours aregreater than 25 there is a 10% premium.d) The gross pay should be rounded to the nearest cent.e) Produce a columnar report, with appropriate headings, showing employeenumber, total hours and gross pay.f) Determine, by hand calculation, what the correct results should befor this…
- Write c++ program we have a=10 Int *p , int **p1, int ***p2 using this do increment in a=10.What are the final values of i, j, k, and *p after executing the following C program segment? int i = 10, j = 20, k = 30; int *p; p = &k; *p = *p + 3; p = &j; *p = 0; p = &i;Consider the letters X and O lined up one after the other as follows. X O X O X O X O X O Develop an algorithm that sorts the X's to the left with the O's to the right (as below) X X X X X O O O O O In one step of your algorithm, it can only replace two adjacent letters. Write the program in C language?
- Write a program in C that take 5 digit number as an input from the user and perform the following tasks:1. Split a number into digits.2. Find the sum of the all the digits in the number.3. Find the product of the all the digits in the number.4. Find maximum number with in the number along with position.5. Printing the digits in the reverse order.Write a complete C++ program that reads a positive and non-zero integer then do the following: 1. Print all odd divisors (factors) of that integer in decreasing order. 2. Print the count of all even divisors. 3. Keep dividing the previous number by 2 until that number reaches zero then print how many times the division was executed. • Example: If the number 20 The odd divisor of 20 is 5, 1 in decreasing order The count of all even divisor is 4 The division was executed 10 timesWrite a c++ program that asks the user to enter an integer number and then by a recursive function find the addition of all integer numbers from 0 to the number user entered. (in your program use a recursive function)
- Knowing that (x + 1)2 = x2 + 2x + 1,and that multiplication is more time consuming than addition, write an efficientprogram that displays the first ten natural numbers and their squares. Knowingthat (x + 1)3 = x3 + 3x2 + 3x + 1, the same process can be followed to displaythe cubes of these numbers.Here is a sample run: 0^2 = 01^2 = 12^2 = 4...8^2 = 649^2 = 8110^2 = 100ANSWER SHOULD BE WRITTEN IN JAVA CODE USING RECURSION Problem Statement Given a string as input return true or false depending on whether it satisfies these rules: 1) The string begins with an 'x' 2) Each 'x' is followed by nothing, 'x' or 'yy' 3) Each 'yy' is followed by nothing or 'x'Write a C++ program: to iteratively compute Fibonacci numbers (named after an Italian mathematician). Some Fibonacci numbers are 1,1,2,3,5,8,... where the next number is found by summing the preceding two numbers. Your program is not assured of recieving good data, thus if -2 is recieved as the number of numbers, then an error should be reported. Try n = 5, 7, 10, -3