Algorithm
Problem Name: beecrowd | 1178
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1178
Array Fill III
Adapted by Neilor Tonin, URI Brazil
Timelimit: 1
Read a number X. Put this X at the first position of an array N [100]. In each subsequent position (1 up to 99) put half of the number inserted at the previous position, according to the example below. Print all the vector N.
Input
The input contains a double precision number with four decimal places.
Output
For each position of the array N print "N[i] = Y", where i is the array position and Y is the number stored in that position. Each number of N[...] must be printed with 4 digits after the decimal point.
Input Sample | Output Sample |
200.0000 |
N[0] = 200.0000 |
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
double n;
cin >> n;
for(int i = 0; i < 100; i++){
cout << fixed << setprecision(4);
cout << "N[" << i << "] = " << n << "\n";
n = n / 2;
}
}
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');
let n = parseFloat(lines.shift());
for(var i = 0; i < 100; i++){
console.log(`N[${i}] = ${(((n).toLocaleString('en-US',{ minimumFractionDigits: 4 })).toString()).replace(/,/g, "")}`);
n = n / 2.0;
}
Copy The Code &
Try With Live Editor
Input
Output
#3 Code Example with Python Programming
Code -
Python Programming
n = float(input())
for i in range(0, 100):
print(f'N[{i}] = {n:.4f}')
n = n / 2
Copy The Code &
Try With Live Editor
Input
Output