Advertisement
cd62131

Calc

Dec 10th, 2013
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.38 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<math.h>
  4. #define PI 3.1415926535
  5.  
  6. typedef struct {
  7.   double rad1, rad2;
  8. } radian_t;
  9.  
  10. radian_t *radian(int, int);
  11. double *keisan_X(double);
  12. double *keisan_Y(double);
  13.  
  14. int main(void) {
  15.   int theta1, theta2, i;
  16.   double X, Y, *x, *y;
  17.   printf("Θ1の値(deg)を入力してください: ");
  18.   scanf("%d", &theta1);
  19.   printf("Θ2の値(deg)を入力してください: ");
  20.   scanf("%d", &theta2);
  21.   radian_t *rad = radian(theta1, theta2);
  22.   X = (cos(rad->rad1) + cos(rad->rad2)) / 2.;
  23.   Y = (sin(rad->rad1) + sin(rad->rad2)) / 2.;
  24.   printf("x = %f, y = %f\n", X, Y);
  25.   x = keisan_X(X);
  26.   y = keisan_Y(Y);
  27.   for (i = 0; i < 4; i++) {
  28.     printf("x[%d] = %f, y[%d] = %f\n", i, x[0], i, y[0]);
  29.   }
  30.   return EXIT_SUCCESS;
  31. }
  32.  
  33. radian_t *radian(int theta1, int theta2) {
  34.   radian_t *rad = (radian_t *) malloc(sizeof(radian_t));
  35.   rad->rad1 = PI * theta1 / 180.;
  36.   rad->rad2 = PI * (theta1 + theta2) / 180.;
  37.   return rad;
  38. }
  39.  
  40. double *keisan_X(double X) {
  41.   int a, i;
  42.   double XX = (0 - X) / 4.;
  43.   double *x = (double *) malloc(4 * sizeof(double));
  44.   for (i = 0, a = 1; i < 4; i++, a++)
  45.     x[i] = X * a * XX;
  46.   return x;
  47. }
  48.  
  49. double *keisan_Y(double Y) {
  50.   int a, i;
  51.   double YY = (0.8 - Y) / 4.;
  52.   double *y = (double *) malloc(4 * sizeof(double));
  53.   for (i = 0, a = 1; i < 4; i++, a++)
  54.     y[0] = Y + a * YY;
  55.   return y;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement