INPUT & OUTPUT FORMAT:
The input is an integer 'n' which denotes the number of terms to be printed in the series.
Print the series and refer the sample output for formatting.
The input is an integer 'n' which denotes the number of terms to be printed in the series.
Print the series and refer the sample output for formatting.
SAMPLE INPUT:
4
SAMPLE OUTPUT:
121 225 361 529
SAMPLE INPUT:
5
SAMPLE OUTPUT:
121 225 361 529 729
4
SAMPLE OUTPUT:
121 225 361 529
SAMPLE INPUT:
5
SAMPLE OUTPUT:
121 225 361 529 729
SOLUTION:
#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int a[n];
a[0] = 121;
int j = 0,i;
for(i = 1; i < n; i++){
a[i] = a[i-1] + 104 + j;
j += 32;
}
for(i = 0; i < n; i++){
cout<<a[i]<<" ";
}
}
using namespace std;
int main()
{
int n;
cin>>n;
int a[n];
a[0] = 121;
int j = 0,i;
for(i = 1; i < n; i++){
a[i] = a[i-1] + 104 + j;
j += 32;
}
for(i = 0; i < n; i++){
cout<<a[i]<<" ";
}
}
No comments:
Post a Comment