Jul 6, 2011 at 2:26am UTC
Help to get the Average of the Last Final results of the 3 Fibonacci Sequence.
I need to create a program that will ask the user to continuously enter a terms number until the user entered 3 fibonacci sequence. And then it will
print out the average of all the numbers entered.
I only need is to get the Average of the 3 final results or the last results of the 3 Fibonacci sequence.
Here's a code of Fibonacci but i don't know how to complete it.
Thanks in advance.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
#include "windows.h"
#include "iostream"
#include "fstream"
using namespace std;
int main() {
//Variables
unsigned long long int a=0;
unsigned long long int b=1;
unsigned long long int c=0;
int terms, terms1, terms2;
int num, num1, num2;
int final;
//Introduction
cout<<"Fibonacci Sequences: Display the Fibonacci sequences to any wishing terms...\n\n" ;
cout<<"Enter the first term: " ;
cin>>terms;
cout<<"Enter the second term: " ;
cin>>terms1;
cout<<"Enter the third term: " ;
cin>>terms2;
cout<<"Fibonacci Sequences, " <<terms<<" terms\n\n" ;
//Main Program
cout<<"1\n" ;
num=terms-1;
for (int seq=0;seq<num;seq++){
c=a+b;
cout<<c<<"\n" ;
a=b;
b=c;
}
cout<<"Fibonacci Sequences, " <<terms1<<" terms\n\n" ;
//Main Program
cout<<"1\n" ;
num1=terms1-1;
for (int seq1=0;seq1<num1;seq1++){
c=a+b;
cout<<c<<"\n" ;
a=b;
b=c;
}
cout<<"Fibonacci Sequences, " <<terms2<<" terms\n\n" ;
//Main Program
cout<<"1\n" ;
num2=terms2-1;
for (int seq2=0;seq2<num2;seq2++){
c=a+b;
cout<<c<<"\n" ;
a=b;
b=c;
}
/*Create a file
ofstream myfile;
myfile.open ("Fibonacci Sequences.txt");
myfile<<"Fibonacci Sequences, "<<terms<<" terms:\n";*/
//myfile<<z<<"\n";
/*END
myfile.close();
cout<<"The sequence was saved to Fibonacci Sequence.txt\n";*/
system("PAUSE" );
return 0;
}
Last edited on Jul 6, 2011 at 4:45am UTC
Jul 13, 2011 at 9:56am UTC
If a user enters 2, 4 and 6, you'll print
1 1
1 1 2 3
1 1 2 3 5 8
and the average you want is (1+3+8)/3. Did I understand you correctly?
If so, have variables int last, last1, last2;
. After every for loop, write last/*or last1 or last2*/ = c;
. Then your average is (last+last1+last2)/3
.
By the way, note that this is a good place to use arrays or functions as you have 3 of everything.