I don't know where I did mistake. :)
Code:#include<stdio.h>
#include<math.h>
int main()
{
printf("%f",pow(11.5,2));
return 1;
}
Printable View
I don't know where I did mistake. :)
Code:#include<stdio.h>
#include<math.h>
int main()
{
printf("%f",pow(11.5,2));
return 1;
}
What makes you think it doesn't work? What do you think the printed value should be?
pow() takes two doubles. "2" should be "2.0", and a program returns 0 rather than 1 if the program works correctly. Returning a non-zero value to the O/S indicates an error, if the return value is checked by the calling program or process.
hahaha...Now, I see what I did. It's because I was at my head that 11.5 * 11.5 was 23. :biggrin::biggrin::biggrin::biggrin::biggrin:
Sorry man.
I have a question... I would like to calculate a^2 = b^2 + c^2... but don't to have variable or loops. Only simple code.
now, how I raise a??Code:#include<stdio.h>
#include<math.h>
int main()
{
printf("%f",pow(11.5,2) + pow(6.3,2));
return 1;
}
It's overkill to use pow to square a number. Just multiply the number by itself. You will need the sqrt function, though. And depending on your system, you might have to add -lm (that's a lowercase L) to the end of your compile command to include the math library.
Code:#include <stdio.h>
#include <math.h>
int main() {
double b = 11.5;
double c = 6.3;
double a_squared = b * b + c * c;
double a = sqrt(a_squared);
printf("%lf\n", a);
return 0;
}