I keep getting "error C2668: 'sqrt' : ambiguous call to overloaded function"
I dont get any errors when I compile. I imagine the problem is that "sqrt" is overloaded, and the way your calling it, the compiler doesnt know which version of "sqrt" to call. Basically, casting "i" to some type should fix the problem. I.e., do something like "sqrt( (double) i)" so it knows to use the version of "sqrt" that takes argument of type "double" (or cast to float, doesnt matter in this case).
Next (keeping in mind the error mentioned above) your for loop does this:
Code:
for(i=1;i<=n;i++) //cycle through 1 to n
printf ("The numbers are: %d",i);
But you probably wanted everything inside the for loop, like
Code:
for(i=1;i<=n;i++) //cycle through 1 to n
{
printf ("The numbers are: %d",i);
i = (sqrt (i));
printf ("\nsqrt = %lf\n",i);
}
Next (again keeping in mind the error mentioned above) you dont want to do
Code:
i = (sqrt (i));
printf ("\nsqrt = %lf\n",i);
. Because your changing "i", which is only supposed to change at the end of each iteration, by 1, which is handled by the "i++" part in the for loop--dont change that. You want to create a different variable, so do something like:
Code:
for(i=1;i<=n;i++) //cycle through 1 to n
{
float result = sqrt (i); // cast i to the appropriate type if you get errors
printf ("\nsqrt(%d) = %f\n", i, result); // (1)
}
And finally, instead of always printing this (the line with (1)), you want to check if the result is even. See my first reply for the "fmod" function. Basically, a number is even if its division by 2 is 0, which is the same thing as its modulo 2 being 0 (i.e. fmod of result by 2 being 0).