Input Format:
The input is an integer 'n' which denotes the number of terms to be printed in the series.
Output Format:
Print the series and refer the sample output for formatting.
Sample Input 1:
6
Sample Output:
6 11 21 36 56 81
Sample Input 2:
10
Sample Output:
6 11 21 36 56 81 111 146 186 231
Solution:
#include<iostream>
using namespace std;
int main(){
int n,i,j = 1;
cin>>n;
int a[n];
a[0] = 6;
for(i = 1; i < n; i++){
a[i] = a[i-1] + 5 * j;
j += 1;
}
for(i = 0; i < n; i++){
cout<<a[i]<<" ";
}
return 0;
}
No comments:
Post a Comment