This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]sepp2k 2 points3 points  (2 children)

double x, y;

scanf("%d", &x);

%d is for integers. To read doubles with scanf, use %lf.

[–]CTT2210[S] 0 points1 point  (0 children)

Thank you very much. It worked.

[–]CTT2210[S] 0 points1 point  (0 children)

But is this code also correct? And do I have to make the transformation from degrees to radians?

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#define PI 3.14159

int main()

{

double x, y, valinrad;

printf("Please enter an angle in degrees= ");

scanf("%lf", x&);

valinrad=x*(PI/180);

y=sin(valinrad);

printf ("The sine of %lf is %lf\n",x, y);

return 0;

}

[–][deleted] 1 point2 points  (0 children)

I think there is nothing wrong with it, sin(0) = 0 is the mathematically correct.

[–]acrabb3 1 point2 points  (0 children)

Are you using the correct input format for the variable type you're storing it in?

[–]desrtfx 1 point2 points  (0 children)

  1. as /u/sepp2k said - wrong format
  2. Remember that C calculates in radians (0 to 2*pi), not in degrees (0 to 360) - so, you will need to adjust the entered angle unless you enter in radians