#include <iostream>
int main()
{
short int N;
std::cin >> N;
int* a = new int[N];
for(int i = 0; i < N; i++)
if(i % 2 == 0)
a[i] = i*i;
}
else
if(i + 1 == N)
a[i] = (a[i-1] + N*N) / 2 + i;
a[i] = (a[i-1] + (i+1) * (i+1)) / 2 + i;
std::cout << a[i] << " ";
std::cout << std::endl;
delete[] a;
g++ compiler
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <iostream>
int main()
{
short int N;
std::cin >> N;
int* a = new int[N];
for(int i = 0; i < N; i++)
{
if(i % 2 == 0)
{
a[i] = i*i;
}
else
{
if(i + 1 == N)
a[i] = (a[i-1] + N*N) / 2 + i;
else
a[i] = (a[i-1] + (i+1) * (i+1)) / 2 + i;
}
std::cout << a[i] << " ";
}
std::cout << std::endl;
delete[] a;
}
g++ compiler