Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<math.h>
- #include<iomanip>
- using namespace std;
- int main()
- {
- float a1 = 2, a2 = 1, a;
- int n;
- cin >> n;
- if (n == 1)
- {cout<<"a1="<<a1<<endl;}
- if (n == 2)
- {cout<<"a1="<<a1<<endl<<"a2="<<a2<<endl;}
- if (n>=3)
- {{cout<<"a1=2"<<endl<<"a2=1"<<endl;}
- for (int i = 3; i <= n; i++)
- {
- a=(((2.0/3.0)*a1)-((1.0/3.0)*(pow(a2,2))));
- a1=a2; a2=a;
- cout<<setprecision(10)<<"a"<<i<<"="<<a<<endl;}}
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement