Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Rewrite the given program to follow these instructions:
The program in the
Whether the first number entered by the user is less than or equal to the second number and whether both the numbers are nonnegative.
Whether the user entered a valid value for the position of the desired number in the Fibonacci sequence.
Rewrite that program so that it checks for these things.
the program:
//*************************************************************
// Author: D.S. Malik
//
// Program: nth Fibonacci number
// Given the first two numbers of a Fibonacci sequence, this
// determines and outputs the desired number of the Fibonacci
// sequence.
//*************************************************************
#include <iostream>
using namespace std;
int main()
{
//Declare variables
int previous1;
int previous2;
int current;
int counter;
int nthFibonacci;
cout << "Enter the first two Fibonacci numbers: "; //Step 1
cin >> previous1 >> previous2; //Step 2
cout << endl;
cout << "The first two Fibonacci numbers are " << previous1 << " and " << previous2 << endl; //Step 3
cout << "Enter the position of the desired Fibonacci number: " ; //Step 4
cin >> nthFibonacci; //Step 5
cout << endl;
if (nthFibonacci == 1) //Step 6.a
current = previous1;
else if (nthFibonacci == 2) //Step 6.b
current = previous2;
else //Step 6.c
{
counter = 3;
//Steps 6.c.2 – 6.c.5
while (counter <= nthFibonacci)
{
current = previous2 + previous1;
previous1 = previous2;
previous2 = current;
counter++;
}//end while
}//end else
/* Output the Fibonacci number at nth position */
return 0;
}//end main
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 5 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Write Algorithm for a program that asks the user to enter two numbers. Then ask the user to enter 1 to add these numbers or 2 to multiply these numbersarrow_forwardWrite an algorithm that asks the user to enter 10 test scores and do the following:(a) Print out the highest and lowest scores.(b) Print out the average of the scores.(c) Print out the second largest score.(d) If any of the scores is greater than 100, then after all the scores have been entered, print a message warning the user that a value over 100 has been entered.(e) Drop the two lowest scores and print out the average of the rest of them.arrow_forwardThe correct statements are: (ab)*a = a(ba)* (a U b)* b (a U b)* = a*b (a U b)* (a U b)* ba (a U b)* U a*b* = (a U b)* □ (a U b)* b (a U b)* U (a U b)* a (a U b)* = (a U b)*arrow_forward
- 2. Need help creating a SPIM program for question #1.arrow_forwardExercise 4 Take in one number and check if it is even or odd. Then, print out the number and tell me if it is even or odd. I # Take in one number and check if it is even or odd # print out the number and tell me if it is even or oddarrow_forwardHelp with my homework. Thank you so much.arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education