Convert string to double: how to use atof
#include <stdio.h>
#include <math.h>
int main ()
{
double n, m;
double pi = 3.1415926535;
char str[256];
printf ( "Enter degrees: " );
gets ( str );
n = atof ( str );
m = sin (n * pi / 180);
printf ( "sine of %f degrees = %f\n" , n, m );
return 0;
}
Related examples in the same category