CodeChum Programming Solution | C++ program to solve a sequence of numbers | AskTheCode
Problem:
All Your Base 7 Are Belong to Us by CodeChum.
MWAHAHA *evil laugh* ?
I am evil space person trying to invade your base, Base 7. I was sent here by my superiors to eradicate all intellectually inferior people, and I was told that people inside your base are part. I will give you chance, however. If you manage to solve this simple sequence of numbers, I will spare you and everyone inside Base 7.
Input Format:
A single line containing an integer.
Input Sample:
5
Output Format:
A single line containing n integers.
Output Sample:
4 9 21 40 66
Code:
#include <iostream>
using namespace std;
int main(){
int n;
cin >> n;
int arr[n];
int prev = 4;
arr[0] = prev;
for (int i = 1; i < n; i++){
arr[i] = prev + 7 * i - 2;
prev = arr[i];
}
for (int i = 0; i < n; i++)
cout << arr[i] << " ";
return 0;
}
Commentaires