第2回 (5/13) 演習の解答例

課題1

#include <stdio.h>

int main(void)
{
    int a = 3;
    float b = 1.2;
    float result1 = a * b;
    float result2 = 2 / a;
    float result3 = 2.0 / a;
    a = b;
    printf("%f\n", result1);
    printf("%f\n", result2);
    printf("%f\n", result3);
    printf("%d\n", a);
    
    return 0;
}

課題2

#include <stdio.h>
#include <math.h>

int main(void)
{
  float pi = 3.1415926;
  float x = 0.2;
  float a, b, c;
  printf("sin(pi)=%f, cos(pi)=%f\n", sin(pi), cos(pi));
  a = sin(x);
  b = cos(x);
  c = a*a + b*b;
  printf("sin^2(x)+cos^2(x)=%f\n", c);
  return 0;
}

Updated: