Răspuns:
using namespace std;
#include <iostream>
#include <stdlib.h>
#include <math.h>
int main() {
int s,x,n,i;
x=1;
s=0;
cout<<"Numarul de termeni ";
cin>>n;
cout<<"Termenii \n";
for(i=1;i<=n;i++){
if (x==1) {
cout<<x<<" ";
s=s+1;
x=x+1;
}
else
if (x==2) {
cout<<x<<" ";
s=s+2;
x=x+1;
}
else
if (x==3) {
cout<<x<<" ";
s=s+3;
x=1;
};
}
cout<<"Suma "<<s;
}