I have a problem with rounding. I need a 6 decimal precision and in "spoj" i get a good result, but the cout or printf round my outcome to 2 decimals. I tried using printf but still console rounds my outcome. How can i avoid this?
#include <iomanip>
#include <string>
void spoj(double** tab, double* vector, int columns, int rows)
{
double** tab_t = new double* [columns];
for (int i = 0; i < columns; i++)
{
tab_t[i] = new double[rows];
}
for (int i = 0; i < columns; i++)
{
for (int j = 0; j < rows; j++)
{
tab_t[i][j] = tab[j][i];
}
}
//for (int i = 0; i < columns; i++)
//{
// for (int j = 0; j < rows; j++)
// {
// std::cout << tab_t[i][j] << " ";
// }
// std::cout << "\n";
//}
double* outcome = new double[columns];
for (int i = 0; i < columns; i++)
{
outcome[i] = 0;
for (int j = 0; j < rows; j++)
{
outcome[i] += tab_t[i][j] * vector[j];
}
}
for (int i = 0; i < columns; i++)
{
printf("%.6f", outcome[i]);
std::cout << " ";
}
}