Algorithm
Problem Name: beecrowd | 1159
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1159
Sum of Consecutive Even Numbers
Adapted by Neilor Tonin, URI Brazil
Timelimit: 1
The program must read an integer X indefinite times (stop when X=0). For each X, print the sum of five consecutive even numbers from X, including it if X is even. If the input number is 4, for example, the output must be 40, that is the result of the operation: 4+6+8+10+12. If the input number is 11, for example, the output must be 80, that is the result of 12+14+16+18+20.
Input
The input file contains many integer numbers. The last one is zero.
Output
Print the output according to the example below.
Input Sample | Output Sample |
4 |
40 |
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <cstdio>
int main() {
int n;
while (scanf("%d", &n) && n) {
if (n % 2) n++;
printf("%d\n", 5 * n + 20);
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
#2 Code Example with Javascript Programming
Code -
Javascript Programming
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const lines = input.split('\n');
while(true){
let n = Number(lines.shift());
let soma = 0;
if(n === 0){
break;}
for(var i = n; i < n+10; i++){
if(i % 2 === 0){
soma+=i;}
}
console.log(soma>;
}
Copy The Code &
Try With Live Editor
Input
Output
#3 Code Example with Python Programming
Code -
Python Programming
while(True):
b = 0
sum = 0
x=int(input())
if(x==0):
break
if(x%2!=0):
x+=1
for a in range(5):
sum=sum+x
x=x+2
print(sum)
Copy The Code &
Try With Live Editor
Input
Output