- 4
Guys pls help meee. Pleasseee
How to make a program using FOR LOOP create a Fibonacci sequence and MULTIPLICATION TABLE . But FOR loop will be used Twice only. THE BASIC ONE. 1,1,2,3,5,8,13,21,34, PLEASE. HELP ME GUYSS .
3 Answers
+ 2
If you know arrays is simple but you have to introduce how many times you want it to do the operation. otherwise it will never stop.
#include <iostream>
using namespace std;
int i,v[1000],j,n;
int main() {
cin>>n;
v[1]=1;
for(i=2;i<=n;i++)
v[i]=v[i-1]+v[i-2];
for(i=1;i<=n;i++)
cout<<v[i]<<" ";
return 0;
}
+ 2
#include <iostream>
using namespace std;
int i,x,j,n;
int main() {
cin>>n;
x=1;
j=1;
int ok=0;
cout<<x<<" "<<j<<" ";
for(i=3;i<=n;i++)
{
if(ok==0)
{x=x+j;
cout<<x<<" ";
ok=1;
}
else
{
j=x+j;
cout<<j<<" ";
ok=0;
}
}
return 0;
}
0
Were not allowed to use anything but ONLY FOR LOOP