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
Air enters a compressor operating at steady state at 1.05 bar, 300 K, with a volumetric flow rate of "84" m3/min and exits at 12
Nina [5.8K]

Answer:

W = - 184.8 kW

Explanation:

Given data:

P_1 = 1.05 bar

T_1 = 300K

\dot V_1 = 84 m^3/min

P_2 = 12 bar

T_2 = 400 K

We know that work is done as

W = - [ Q + \dor m[h_2 - h_1]]

forP_1 = 1.05 bar,  T_1 = 300K

density of air is 1.22 kg/m^3 and h_1 = 300 kJ/kg

for P_2 = 12 bar, T_2 = 400 K

h_2 = 400 kj/kg

\dot m = \rho \times \dor v_1 = 1.22 \frac{84}{60} =1.708 kg/s

W = -[14 + 1.708[400-300]]

W = - 184.8 kW

8 0
3 years ago
Carbon dioxide (CO2) is compressed in a piston-cylinder assembly from p1 = 0.7 bar, T1 = 320 K to p2 = 11 bar. The initial volum
tekilochka [14]

Answer:

W_{12}=-53.9056KJ

Part A:

Q=-7.03734 KJ/Kg (-ve sign shows heat is getting out)

Part B:

Q=1.5265KJ/Kg (Heat getting in)

The value of Q at constant specific heat is approximately 361% in difference with variable specific heat and at constant specific heat Q has opposite direction (going in) than Q which is calculated in Part B from table A-23. So taking constant specific heat is not a good idea and is questionable.

Explanation:

Assumptions:

  1. Gas is ideal
  2. System is closed system.
  3. K.E and P.E is neglected
  4. Process is polytropic

Since Process is polytropic so  W_{12} =\frac{P_{2}V_{2}-P_{1}V_{1}}{1-n}

Where n=1.25

Since Process is polytropic :

\frac{V_{2}}{V_{1}}=(\frac{P_{1}}{P_{2}})^{\frac{1}{1.25}} \\V_{2}= (\frac{P_{1}}{P_{2}})^{\frac{1}{1.25}} *V_{1}

V_{2}= (\frac{0.7}{11})^{\frac{1}{1.25}} *0.262\\V_{2}=0.028924 m^3

Now,W_{12} =\frac{P_{2}V_{2}-P_{1}V_{1}}{1-n}

W_{12} =\frac{11*0.028924-0.7*0.262}{1-1.25}(\frac{10^{5}N/m^2}{1 bar})(\frac{1  KJ}{10^{3}Nm})

W_{12}=-53.9056KJ

We will now calculate mass (m) and Temperature T_2.

m=\frac{P_{1}V_{1}}{RT_{1}}\\ m=\frac{0.7*0.262}{\frac{8.314KJ}{44.01Kg.K}*320}(\frac{10^{5}N/m^2}{1 bar})(\frac{1  KJ}{10^{3}Nm})\\m=0.30338Kg

T_{2} =\frac{P_{2}V_{2}}{Rm}\\ m=\frac{11*0.028924}{\frac{8.314KJ}{44.01Kg.K}*0.30338}(\frac{10^{5}N/m^2}{1 bar})(\frac{1  KJ}{10^{3}Nm})\\T_{2} =555.14K

Part A:

According to energy balance::

Q=mc_{v}(T_{2}-T_{1})+W_{12}

From A-20, C_v for Carbon dioxide at 300 K is 0.657 KJ/Kg.k

Q=0.30338*0.657(555.14-320)+(-53.9056)

Q=-7.03734 KJ/Kg (-ve sign shows heat is getting out)

Part B:

From Table A-23:

u_{1} at 320K = 7526 KJ/Kg

u_{2} at 555.14K = 15567.292 (By interpolation)

Q=m(\frac{u(T_{2})-u(T_{1})}{M} )+W_{12}

Q=0.30338(\frac{15567.292-7526}{44.01} )+(-53.9056)

Q=1.5265KJ/Kg (Heat getting in)

The value of Q at constant specific heat is approximately 361% in difference with variable specific heat and at constant specific heat Q has opposite direction (going in) than Q which is calculated in Part B from table A-23. So taking constant specific heat is not a good idea and is questionable.

7 0
4 years ago
7. An energy auditor is part of what career field?
Rashid [163]
An energy auditor is part of power operations
6 0
2 years ago
Is a gas turbine a heat engine?
Nookie1986 [14]
Gas turbines extract the energy from combustion gas

and heat engines convert thermal and chemical energy to mechanical energy

gas is considered a chemical so i'm pretty sure it is considered one
4 0
3 years ago
Giving free brainlist first 1
kaheart [24]

Hi! Hope you're having a great day!

8 0
3 years ago
Other questions:
  • A hot-water stream at 80°C enters a mixing chamber with a mass flow rate of 0.56 kg/s where it is mixed with a stream of cold wa
    7·1 answer
  • What is the name for a part of a window that joins two windows into a single unit?
    12·1 answer
  • A diameter shaft contains a deep U-shaped groove that has a radius at the bottom of the groove. The maximum shear stress in the
    6·1 answer
  • What is cooking with a fossil fuel? What is a fossil fuel?
    7·1 answer
  • Consider an aircraft powered by a turbojet engine that has a pressure ratio of 9. The aircraft is stationary on the ground, held
    9·1 answer
  • You are traveling along an interstate highway at 32.0 m/s (about 72 mph) when a truck stops suddenly in front of you. You immedi
    11·1 answer
  • For the example above: If the three balls were all whites or all blues?​
    14·1 answer
  • What is 3'-9" in feet?
    11·1 answer
  • Which of the following is not an electronic device ?
    11·1 answer
  • et G = (V, E) be a directed graph in which each vertex in u E V is labeled with a unique integer L(u) from the set {1, 2 ...,V]}
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!