Answer:
#include <stdio.h>
int fib(int n) {
if (n <= 0) {
return 0;
}
if (n <= 2) {
return 1;
}
return fib(n-1) + fib(n-2);
}
int main(void) {
for(int nr=0; nr<=20; nr++)
printf("Fibonacci %d is %d\n", nr, fib(nr) );
return 0;
}
Explanation:
The code is a literal translation of the definition using a recursive function.
The recursive function is not per se a very efficient one.
Only when the count is 0 will the if statement's statement block be executed because of the if count == 0 condition.
<h3>What is an if statement?</h3>
- A program is guided to make decisions based on predetermined criteria using the IF statement, which is a decision-making statement.
- If a certain condition is satisfied (TRUE), one piece of code is run, and if it is not, another set of code is run, and so on.
- A conditional statement, also called a conditional expression, conditional flow statement, or conditional processing, is a set of guidelines that are followed when a specific condition is satisfied.
- Because IF a condition is satisfied, THEN an action is taken, it is sometimes referred to as an If-Then statement.
To learn more about if statement, refer to:
brainly.com/question/18736215
#SPJ4
Answer:
total = 0
items = int(input("Enter the number of items ordered: "))
for i in range(items):
price = float(input("Enter the price of item " + str(i+1) + ": "))
total += price
if total < 200:
total += (items * 10)
print("Bill is $" + str(total))
Explanation:
*The code is in Python.
Ask the user to enter the number of items ordered
Create a for loop that iterates depending on the number of items ordered. Inside the loop, ask the price of each item and add it to the total
After the loop, check the total. If it is smaller than 200, add 10 for each item to the total
Print the total
2 2 1 1 i think i may be wrong tho