I hardly know any math, but I put this together by looking at other suggestions. It feels a bit roundabout, although I can’t put my finger on it. At least it gets the desired result.
[code]#include <stdio.h>
// Including math library #include <math.h>
int main (int argc, const char * argv[])
{
// Declaring x to be 1.0
double x = (1.0);
// Declaring variable "result" to be sin(x).
double result = sin(x);
// Prints the variable "result" with 3 decimals.
printf("The sine of 1 radian is %.3f.\n", result);
return 0;
Iromao linked the definitive answer. To try and answer more simply, it’s an alternative way to measure an angle instead of degrees.
Where a degree is what you get when you slice a circle 360 slices, a radian is what you get when you slice a circle up into slices the same length as the circle’s radius.
Since we know the circumference of a circle is 2 times (pi) times the radius [ C=2(pi)r ]
If we say that the radius of the circle is one “unit” then [ C=2(pi)(1) ] or [ C=2(pi) ]
So there are 2(pi) radians in any circle (or approximately 6.28)
This is my solution for Challenge
I’ve some explanation in commentary
[code]#include <stdio.h> #include <math.h> // include the library for your calculation
int main(int argc, const char * argv[])
{
double sin(double x);// This is a function that takes one argument "(double x) "
double radiantOf1 = sin(1); // Create a variable that use the "sin function" to calculate and store the result
printf(" Your answer is: %.3f\n" ,radiantOf1); //Print out the result with 3 numbers after "."
return 0;
}
[/code]
The result is as you would expected
Your answer is: 0.841
Program ended with exit code: 0
[code]/* Use the math library!
Add code to main.c that displays the sine of 1 radian.
Show the number rounded to three decimal points. It should be 0.841.
The sine function is declared like this: double sin(double x);
*/
#include <stdio.h> #include <math.h>
double calculatedSin(double x){
double sine = sin(x);
return sine;
}
int main(int argc, const char * argv[]) {
double x = 1.0; // 1 radian
printf("Sine of 1 radian is %0.3f \n",calculatedSin(x));
return 0;
}[/code]
result:
[quote]Sine of 1 radian is 0.841
Program ended with exit code: 0[/quote]
I got the code to work but, I don’t know what the question meant by using double sin(double x) ??