I'm trying out the pow-function in c, and something goes wrong.
#include <math.h>
#include <stdio.h>
int main(){
int highnumber = 18;
int input = 344;
int diff[18];
for(int j = 1; j<=highnumber; j++){
diff[j-1] = input - pow(j,2);
printf("%d\n",diff[j-1]);
}
}
I get the output:
343
340
335
328
319
308
295
280
263
244
223
200
175
147
119
88
54
19
Now the last two entries, doesn't make sense to me. They should be 55 and 20. Anyone knows why this happens?
Okay, I change the indexing, and show that pow function works:
#include <math.h>
#include <stdio.h>
int main(){
int highnumber = 18;
int input = 344;
int diff[18];
for(int j = 0; j<=highnumber; j++){
diff[j] = input - pow(j,2);
printf("%d\n",diff[j]);
}
int a = input - pow(17,2);
int b = input - pow(18,2);
printf("%d\n%d",a,b);
}
Output:
344 343 340 335 328 319 308 295 280 263 244 223 200 175 147 119 88 54 19 55 20