#include <iostream>
#include <iomanip>
#include <math.h>
int main(){
unsignedlonglong inputstream;
unsignedlonglong array[4] = {}; //I used magic numbers to debug
int arrayPlace = 0;
while (std::cin >> inputstream ){
array[arrayPlace] = sqrt(inputstream);
arrayPlace++;
}
std::cout << std::fixed;
std::cout << std::setprecision(4);
for ( size_t i = arrayPlace - 1; i >= 0; i--)////<---Loop goes into random arrays
std::cout << array[i] << " ";
}
The main problem I have is that
a) When I register the sqrt product into the array for some reason it truncates my number into an integer
b) My for loops goes past the boundaries despite the fact that my condition stops at i >= 0
Problem 1001:
Input The input stream contains a set of integer numbers Ai (0 ≤ Ai ≤ 1018). The numbers are separated by any number of spaces and line breaks. A size of the input stream does not exceed 256 KB. Output
For each number Ai from the last one till the first one you should output its square root. Each square root should be printed in a separate line with at least four digits after decimal point.
1) Your array is an array of integers. So it is natural that any floating point value will ne truncated to integer.
2) size_t is unsigned type. It cannot represent values below 0. When you try to decrement 0, you will get largest possible value.
3) No it would not. Unless you profile your program and fing vector operations being the bottleneck.
Alright thanks! I've solved the problem of accessing random memory in the array.
Going to the point about my array of integers. By declaring my array unsignedlonglong wouldn't that be enough to make it an array of unsigned long long?