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
slava [35]
3 years ago
15

Write a iterative function that finds the n-th integer of the Fibonacci sequence. Then build a minimal program (main function) t

o test it. That is, write the fib() solution as a separate function and call it in your main() function to test it. For reference see Fibonacci number. INPUT OUTPUT (0, 2) (1, 3) (2, 5) 5 INPUT: OUTPUT: (0, 2) (1, 3) (2, 5) (3, 8) (4, 13) 13 INPUT: OUTPUT: (0, 2) 6765 (1, 3) (2, 5) (3, 8) (4, 13) (5, 21) (6, 34) (7, 55) (8, 89) (9, 144) (10, 233) Note, the first number in the pair is the iteration count (i) and the second number is the value of the (i+2)-th Fibonacci value. Problem 2 Write a recursive function that finds the n-th integer of the Fibonacci sequence. Then build a minimal program to test it. For reference see Fibonacci number. To check for recursion, please have the Fibonacci function print out its input as shown in the examples below: INPUT: OUTPUT: fib(5) fib(4) fib(3) fib(2) fib(1) fib(0) fib(1) fib(2) fib(1) fib(0) fib(3) fib(2) fib(1) INPUT: OUTPUT: fib(7) fib(6) fib(5) fib(4) fib(3) fib(2) fib(1) fib(0) fib(1) fib(2) fib(1) fib(0) fib(3) 13 Problem 3 In this problem, you need to print the pattern of the following form containing the numbers from 1 to n: 4 4 4 4 4 4 4 4 3 3 3 3 3 4 4 3 2 2 2 3 4 4 3 2 1 2 3 4 4 3 2 2 2 3 4 4 3 3 3 3 3 4 4 4 4 4 4 4 4 Example when n=4. INPUT Input contains a single integer n. CONSTRAINTS • 1 <= n <= 1000 OUTPUT Print the pattern mentioned in the problem statement. EXAMPLES: INPUT: INPUT: OUTPUT: 2 2 2 2 1 2 2 2 2 INPUT: 5 OUTPUT: 5 5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 4 5 5 4 3 3 3 3 3 4 5 5 4 3 2 2 2 3 4 5 5 4 3 2 1 2 3 4 5 5 4 3 2 2 2 3 4 5 5 4 3 3 3 3 3 4 5 5 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 INPUT: 7 INPUT: 7 OUTPUT: 7 7 7 7 7 7 7 7 7 7 7 7 7 7 6 6 6 6 6 6 6 6 6 6 6 7 7 6 5 5 5 5 5 5 5 5 5 6 7 7 6 5 4 4 4 4 4 4 4 5 6 7 7 6 5 4 3 3 3 3 3 4 5 6 7 7 6 5 4 3 2 2 2 3 4 5 6 7 7 6 5 4 3 2 1 2 3 4 5 6 7 7 6 5 4 3 2 2 2 3 4 5 6 7 7 6 5 4 3 3 3 3 3 4 5 6 7 7 6 5 4 4 4 4 4 4 4 5 6 7 7 6 5 5 5 5 5 5 5 5 5 6 7 7 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7
Engineering
2 answers:
Natasha2012 [34]3 years ago
7 0

Answer:

Codes for each of the problems are explained below

Explanation:

PROBLEM 1 IN C++:

#include<iostream>

using namespace std;

//fib function that calculate nth integer of the fibonacci sequence.

void fib(int n){

  // l and r inital fibonacci values for n=1 and n=2;

  int l=1,r=1,c;

 

  //if n==1 or n==2 then print 1.

  if(n==1 || n==2){

      cout << 1;

      return;

  }

  //for loop runs n-2 times and calculates nth integer of fibonacci sequence.

  for(int i=0;i<n-2;i++){

      c=l+r;

      l=r;

      r=c;

      cout << "(" << i << "," << c << ") ";

  }

  //prints nth integer of the fibonacci sequence stored in c.

  cout << "\n" << c;

}

int main(){

  int n; //declared variable n

  cin >> n; //inputs n to find nth integer of the fibonacci sequence.

  fib(n);//calls function fib to calculate and print fibonacci number.

}

PROBLEM 2 IN PYTHON:

def fib(n):

   print("fib({})".format(n), end=' ')

   if n <= 1:

       return n

   else:

       return fib(n - 1) + fib(n - 2)

if __name__ == '__main__':

   n = int(input())

   result = fib(n)

   print()

   print(result)

andre [41]3 years ago
6 0

You literally wrote gibberish so how do you expect us to answer this question. Even the other person who answered didn't know what he was talking about. :C

You might be interested in
Plot the absorbance, A, versus the FeSCN2 concentration of the standard solutions (the values from your Pre-lab assignment). Fro
Charra [1.4K]

Answer:

Explanation:

Detailed explanation is done in the attach document.

5 0
3 years ago
If 1 uF capacitor is fully charged with 120 V across it, how much energy is stored in it? (a) 7.2 kJ (b) 7.2 mJ (c) 0.12 mJ (d)
jeyben [28]

Answer:

(b) 7.2 mJ

Explanation:

ENERGY STORED IN CAPACITOR: the energy is stored in capacitor in electric field

which can be calculated by expressions

E=\frac{1}{2} c v{^2}

=\frac{1}{2} 10^{-6}120^{2}

=7200×10^{-6} J

= 7.2×10^{-3} J

=7.2 mJ

4 0
3 years ago
When passing another vehicle, when is it acceptable to drive over the
miss Akunina [59]

Answer:

Under no circumstances

Explanation:

I'm not 100% sure why, but I remember hearing that you're not suposed to go over the speed limit no matter what

7 0
3 years ago
Read 2 more answers
C#: Arrays - Ask the user how many students names they want to store. You will create two parallel arrays (e.g. 2 arrays with th
zhenek [66]

Answer:

  1. using System;      
  2. public class Program
  3. {
  4. public static void Main()
  5. {
  6.  Console.WriteLine("Enter number of students: ");
  7.  int num = Convert.ToInt32(Console.ReadLine());
  8.  string [] firstName = new string[num];
  9.  string [] lastName = new string[num];
  10.  
  11.  for(int i=0 ; i < num; i++){
  12.   Console.WriteLine("Enter first name: ");
  13.   firstName[i] = Console.ReadLine();
  14.    
  15.   Console.WriteLine("Enter last name: ");
  16.   lastName[i] = Console.ReadLine();
  17.  }
  18.  
  19.  for(int j=0; j < num; j++){
  20.   Console.WriteLine(lastName[j] + "," + firstName[j]);
  21.  }
  22. }
  23. }

Explanation:

Firstly, prompt user to enter number of student to be stored (Line 6- 7). Next, create two array, firstName and lastName with num size (Line 8-9).

Create a for-loop to repeat for num times and prompt user to enter first name and last name and then store them in the firstName and lastName array, respectively (Line 11 - 17).

Create another for loop to traverse through the lastName and firstName array and display the last name and first name by following the format given in the question (Line 19 - 21).

4 0
3 years ago
A 4-kW electric heater runs for 2 hours to raise the room temperature to the desired level. Determine the amount of electric ene
Anna35 [415]

Answer:

Q' = 8 KW.h

Q'=28800 KJ

Explanation:

Given that

Heat Q= 4 KW

time ,t = 2 hours

The amount of energy used in KWh given as

Q ' = Q x t

Q' = 4 x  2 KW.h

Q' = 8 KW.h

We know that

1 h = 60 min = 60 x 60 s  = 3600 s

We know that W  = 1 J/s

The amount of energy used in KJ given as

Q' = 8 x 3600 = 28800 KJ

Therefore

Q' = 8 KW.h

Q'=28800 KJ

6 0
3 years ago
Other questions:
  • A circuit-switching scenario in whichNcs users, each requiring a bandwidth of 25 Mbps, must share a link of capacity 150 Mbps.
    12·1 answer
  • . A constant current of 1 ampere is measured flowing into the positive reference terminal of a pair of leads whose voltage we’ll
    10·1 answer
  • an existing highway-railway at-grade crossing is being redesigned as grade separated to improve traffic operations. The railway
    8·1 answer
  • A parison is extruded from a die with outside diameter = 11.5 mm and inside diameter = 7.5 mm. The observed die swell = 1.25. Th
    8·1 answer
  • Its an opinion!!!!
    8·1 answer
  • Marie and James are bubbling dry pure nitrogen (N2) through a tank of liquid water (H2O) containing ethane (C2H6). The vapor str
    5·1 answer
  • ?Why the efficiency of Class A amplifier is very poor​
    11·1 answer
  • Bob would like to run his house off the grid, therefore he needs to find out how many solar panels and batteries he needs to buy
    12·1 answer
  • A helicopter is hovering in a steady cross wind at a gross weight of 3,000 lb (1,360.8 kg). This helicopter has 275 hp (205 kW)
    10·1 answer
  • 4.6. What is the maximum peak output voltage and current if the supply voltages are changed to +15 V and -15 V.​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!