Code: Select all
#include <stdio>
#include <math>//floor, ceil
#include <stdlib>//rand, srand
#include <time>
int main()
{
int i, luku[3];
float tulos;
char anykey[80];
srand (time(NULL));
for (i = 0; i < 3; i++)
luku[i] = rand() % 10;//luku 0 - 9
tulos = luku[0] + (float) luku[1]/10 + (float) luku[2]/100;
printf("Random number is %f\n", tulos);
printf("Rounded up it's %f", (float) ceil(tulos*10) / 10);
printf(" and rounded down it's %f\n", (float) floor(tulos*10) / 10);
gets(anykey);
return 0;
}