What would be the pseudocode and flowchart for this. Just drawing a blank. BTW i
ID: 3551683 • Letter: W
Question
What would be the pseudocode and flowchart for this. Just drawing a blank. BTW it shows fibonacci numbers below 100.
#include<iostream>
using namespace std;
int main()
{
double c, first = 0, second = 1, next;
cout << "First 100 terms of Fibonacci series are:" << endl;
for ( c = 0 ; c < 100 ; c++ )
{
if ( c <= 1 )
next = c;
else
{
next = first + second;
first = second;
second = next;
}
cout << next << endl;
}
return 0;
}
Explanation / Answer
* Start with the beginning of the sequence or set the sequence at the first two numbers * n1 = 0 * n2 = 1 * Print "First 100 terms of Fibonacci series are:" * n2 is our current number and n1 is our preceding number. * Add these two numbers together to get the next number in the sequence(n3). * n3 = n1 + n2 * Print N3 * n1 = n2 * n2 = n3 * loop back to n3 = n1 + n2psuedocode for finding fibonacci numbers under 100
* Start with the beginning of the sequence or set the sequence at the first two numbers * n1 = 0 * n2 = 1 * Print "Fibonacci number under 100 are:" * n2 is our current number and n1 is our preceding number. * Add these two numbers together to get the next number in the sequence(n3). * n3 = n1 + n2 * if n3 greater than 100 quit * Print N3 * n1 = n2 * n2 = n3 * loop back to n3 = n1 + n2
#include<iostream> using namespace std; int main() { double c, first = 0, second = 1, next; cout << "First 100 terms of Fibonacci series are:" << endl; for ( c = 0 ; 1 ; c++ ) { if ( c <= 1 ) next = c; else { next = first + second; if(next > 100) break; first = second; second = next; } cout << next << endl; } return 0; }
Changes made:
1. Removed the condition in for loop and replaced it with 1 which makes it run forever unless broken. 2. if(next > 100) break; after claculating next. This breaks the loop is next is more than 100. * Start with the beginning of the sequence or set the sequence at the first two numbers * n1 = 0 * n2 = 1 * Print "Fibonacci number under 100 are:" * n2 is our current number and n1 is our preceding number. * Add these two numbers together to get the next number in the sequence(n3). * n3 = n1 + n2 * if n3 greater than 100 quit * Print N3 * n1 = n2 * n2 = n3 * loop back to n3 = n1 + n2
#include<iostream> using namespace std; int main() { double c, first = 0, second = 1, next; cout << "First 100 terms of Fibonacci series are:" << endl; for ( c = 0 ; 1 ; c++ ) { if ( c <= 1 ) next = c; else { next = first + second; if(next > 100) break; first = second; second = next; } cout << next << endl; } return 0; }
Changes made:
1. Removed the condition in for loop and replaced it with 1 which makes it run forever unless broken. 2. if(next > 100) break; after claculating next. This breaks the loop is next is more than 100.
#include<iostream> using namespace std; int main() { double c, first = 0, second = 1, next; cout << "First 100 terms of Fibonacci series are:" << endl; for ( c = 0 ; 1 ; c++ ) { if ( c <= 1 ) next = c; else { next = first + second; if(next > 100) break; first = second; second = next; } cout << next << endl; } return 0; }
Changes made:
1. Removed the condition in for loop and replaced it with 1 which makes it run forever unless broken. 2. if(next > 100) break; after claculating next. This breaks the loop is next is more than 100.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.