This code is written in C++:
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
#include <conio.h>
#include <math.h>
#define MAX 100
int main(){
int n, k, s = 0, cnt = 1, t[MAX] = {0};
cout<<"Submit an entry n: ";
cin>>n;
if((n < 5)||((n-5)%3)){
cout<<endl<<"Entry n does not exist in the series.";
cout<<endl<<"The sum S is 0."<<endl;
cout<<endl<<"There are no multiples of 4 between the numbers of n.";
}
else{
for(int i = 5; i <= n; i = i + 3){
(i%2) ? s = s + i : s = s - i; // Calculate sum S
if(!(i%4)){ // Determining multiples of 4 between the numbers of n
t[cnt] = i;
cnt++;
}
}
cout<<"The sum S is "<<s<<endl<<endl;
cout<<endl<<"The multiples of 4 between the numbers of n are:"<<endl;
for (int i = 0; i <= cnt-1; i++)
(i==cnt-1)? cout<<t[i]<<endl<<endl : cout<<t[i]<<" - ";
cout<<"Specify the entry position value k: ";
cin>>k;
cout<<endl<<"The kth entry in the series is: "<<pow(-1,k+1)*(2+3*k)<<endl;
}
getch();
return 0;
}
Sample example:
Submit an entry n: 305
The multiplesof 4 between the numbers of n are:
0 - 8 - 20 - 32 - 44 - 56 - 68 - 80 - 92 - 104 - 116 - 128 - 140 - 152 - 164 - 176 - 188 - 200 - 212 - 224 - 236 - 248 - 260 - 272 - 284 - 296
The sum S is 155
Specify the entry position k: 100
The kth entry in the series is: -302
If you don't care if the multiples of 4 between the numbers of n are displayed before the sum S, and you don't want to define an array whose size will ultimately be exhausted and use it to save the multiples of 4, then the code can be re-written as:
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
#include <conio.h>
#include <math.h>
int main(){
int n, k, s = 0;
cout<<"Submit an entry n: ";
cin>>n;
if((n < 5)||((n-5)%3)){
cout<<endl<<"Entry n does not exist in the series.";
cout<<endl<<"There are no multiples of 4 between the numbers of n.";
cout<<endl<<"The sum S is 0."<<endl;
}
else{
for(int i = 5; i <= n; i = i + 3){
(i%2) ? s = s + i : s = s - i; // Calculate sum S
if(!(i%4)) // Determining multiples of 4 between the numbers of n
cout<<i<<" - ";
}
cout<<"The sum S is "<<s<<endl<<endl;
}
cout<<"Specify the entry position value k: ";
cin>>k;
cout<<endl<<"The kth entry in the series is: "<<pow(-1,k+1)*(2+3*k)<<endl;
getch();
return 0;
}
Same sample example gives same results.
However, we didn't check if entries n and k are integers in the first place. So, I'll wait for you to try it, and then I'll post my answer.