Write a program In C language (not C++), write a program for the following 15. P
ID: 3681079 • Letter: W
Question
Write a program In C language (not C++), write a program for the following
15. Produce the nth fibonnaci number in the fibonnaci sequence. Ask the user to input
which number in the sequence that they want to know and then output the appropriate
value. The fibonacci sequence consists of the numbers 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55
etc. So for example if the user asked for the 6th number in the sequence the program
would report the value 5.
16. Which is a better deal? You are given .01 (a penny) on the first day of the month. A
person offers you one of these deals: You can accept either 1 million dollars today or take
the penny which the person will double its value everyday for the entire month of 30 days.
SO on day 1 you will have .01, on day 2 you will have .02, on day 3 you will have .04
etc. At the end of the month you receive the money total as it doubles itself every day.
Which deal is worth the most?
Explanation / Answer
15.
#include<stdio.h>
int fib(int n)
{
int a = 0, b = 1, c, i;
if( n == 0)
return a;
for (i = 3; i <= n; i++)
{
c = a + b;
a = b;
b = c;
}
return b;
}
int main ()
{
int n ;
printf("Enter number: ");
scanf("%d",&n);
printf("%d fibonnacci number is : %d ",n, fib(n));
getchar();
return 0;
}
/*
Output:
Enter number: 6
6 fibonnacci number is : 5
*/
16.
Hi I have written a C program to calculate final amount based on number of days and first day penny amount:
#include<stdio.h>
float calculate(int days, float penny){
int i;
float sum = penny;
for(i=2; i<=days; i++){
sum = sum + sum;
}
return sum;
}
int main ()
{
float penny;
int days;
printf("Enter first day penny amount: ");
scanf("%f",&penny);
printf("Enter number of days: ");
scanf("%d",&days);
float finalAmount = calculate(days, penny);
printf("Final Amount at end of %d days is : $%.2lf ",days, finalAmount);
getchar();
return 0;
}
/*
Output:
Enter first day penny amount: 0.01
Enter number of days: 30
Final Amount at end of 30 days is : $5368709.00
Clearly it is greater than 1 million dollar
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.