#include <iostream> using namespace std; int main() { int high; int low; int odd=0; // Initialize first three Fibonacci Numbers int f1 = 0, f2 = 1, f3 = 1; // Count fibonacci numbers in given range int result = 0; cout << "Enter low and high limits:" << endl; cin >> low; cin >> high; while (f1 <= high) { if (f1 >= low) result++; f1 = f2; f2 = f3; f3 = f1 + f2; // take the numbers that are between low and high only and check to see if they are odd if (f3 >= low && f3 <=high ) { if( f3 % 2 == 1 ) odd++; cout << f3 << " "; //this one could go out of the if stement } } cout << endl; cout << odd << " of the " << result << " numbers printed were odd" << endl; //cout << result << " "; return 0; }
;declaring all my local variables BR main high: .EQUATE 12 ;#2d low: .EQUATE 10 ;#2d odd: .EQUATE 8 ;#2d f1: .EQUATE 6 ;#2d f2: .EQUATE 4 ;#2d f3: .EQUATE 2 ;#2d result: .EQUATE 0 ;#2d main: SUBSP 14,i ;Allocate #high,#low,#odd,#f1,#f2,#f3,#result lda 0,i ; initilize counters odd=0, result=0,f1=0 sta odd,s sta result,s sta f1,s lda 1,i ; initialize f2, and f3 to=1 sta f2,s sta f3,s STRO msg1,d ; message to the screen to enter low and high numbers deci low,s deci high,s ; program is working good from here and up so far while: lda f1,s cpa high,s BRGT endWh if: lda f1,s cpa low,s BRLT while LDA result,s adda 1,i sta result,s lda f1,s adda f2,s sta f1,s lda f2,s adda f3,s sta f2,s lda f3,s adda f1,s adda f2,s sta f3,s br while endWh: deco result,s STOP msg1: .ASCII "Enter low and high limits:\x00" .END