I wrote a program that calculates the cubes of the first five numbers:
#include <stdio.h>
#include <math.h>
int main() {
for(int i = 1; i <= 5; i++) {
printf("%d ",pow(i,3));
}
}
This does not work. It prints:
0 0 0 0 0
However, using float it works:
#include <stdio.h>
#include <math.h>
int main() {
printf("%f\n",pow(3,3));
for(float i = 1; i <= 5; i++) {
printf("%f ",pow(i,3));
}
}
And prints:
1.000000 8.000000 27.000000 64.000000 125.000000
What is the problem with integers? Why does this only work with floating point numbers?