the book says to add code to main.c that displays the sine of 1 radian. show the number rounded to 3 decimal points. it should be 0.841.
pg no.53
chapter-7 number
That’s not wrong, but I would do it like this:
int main (int argc, const char * argv[])
{
const double oneRadian = 1.0;
printf ("sine of 1 radian is %.3f\n", sin (oneRadian));
}
[Become a competent programmer: pretty-function.org]
#include <stdio.h>
#include <math.h>
double sin(double x);
int main(int argc, const char * argv[])
{
float x = 1;
printf(“Sine of 1 radian is %.3f…\n”, sin(x));
return 0;
}
CAN SOMEONE PLEASE TELL ME IF THIS IS CORRECT OR DID I DO IT WRONG.
You don’t need the sine function declaration, since it is already in math.h. The book was just showing how the function was declared.
[quote=“iphonelover”]#include <stdio.h>
#include <math.h>
double sin(double x);
int main(int argc, const char * argv[])
{
float x = 1;
printf(“Sine of 1 radian is %.3f…\n”, sin(x));
return 0;
}
CAN SOMEONE PLEASE TELL ME IF THIS IS CORRECT OR DID I DO IT WRONG.
[/quote]
I came up with the following for the challenge.
[code]#include <stdio.h>
#include <math.h>
int main(int argc, const char * argv[])
{
double sin(double x);
printf("%.3f\n", sin(1));
return 0;
}[/code]