In: Computer Science
The language is C++
Below are a list of sequences of numbers. Your job is to program each sequence with any loop of your preference (while, for, do/while). I want the code to output the sequence provided and the next number in the sequence (you can output more but there is 1 sequence that may only have 1 number after).. Please order and notate each sequence in your output –. The output should also be horizontal like that shown below (if you output it vertically it will be -10pts). Each sequence should be programed with only 1 loop and optionally 1 selection statement. Hint: a selection statement may be used for the last 3 problems.
Series 1:
15, 14, 13, 12, 11, ...
Series 2:
1, 2, 5, 14, 41, ...
Series 3:
2, 3, 5, 8, 12, 17, ...
Series 4:
15, 13, 11, 9, 7, ...
Series 5:
71, 142, 283, 564, 1125, 2246, 4487, 8968, ...
Series 6:
10, 5, 1, -2, -4, -5, -5, -4, -2, ...
Series 7:
0, 1, 3, 7, 15, 31, 63, ...
Series 8:
0, 1, 4, 13, 40, 121, ...
Series 9:
15, 29, 56, 108, 208, 400…
series 10: (finite)
0, 1, 3, 6, 10, 10, 11, 13, 16, 16, 17, 19, 19, ...
series 11:
7, 9, 14, 20, 27, 33, 42, 52, 63, 73, 86, ...
Series 12:
13, -21, 34, -55, 89 ...
Series 13:
0, 1, 4, 12, 32, 80, 192, ...
Coding
#include <iostream>
using namespace std;
int main(){
int j,sum;
//Seriese 1 15, 14, 13, 12, 11, ...
cout<<"Seriese 1"<<endl;
for(int i=15; i>=10; i--){
cout<<i<<",";
}
cout<<endl<<"Seriese 2"<<endl;
sum=3;
j=0;
cout<<"1"<<","<<"2"<<",";
for(int i=2; i<=41;){
j=i+sum;
cout<<j<<",";
sum=sum*3;
i=j;
}
cout<<endl<<"Seriese 3"<<endl;
j=0;
sum=2;
for(int i=0; i<=6; i++){
sum=sum+i;
cout<<sum<<",";
}
cout<<endl<<"Seriese 4"<<endl;
for(int i=15; i>=4; i=i-2){
cout<<i<<",";
}
return 0;
}
output:
if you still have any Problem regarding this question please comment and if you like my code please appreciate me by thumbs up thank you.........