---2.1--- #include #include int main(void) { int h, w, s; double f, stdw; printf("身長,体重,性別を入力して下さい:"); scanf("%d%d%d", &h, &w, &s); if (s == 1) /* 男 */ stdw = (h - 139) * 0.613 + 42.2; else /* 女 */ stdw = (h - 139) * 0.510 + 43.2; f = (w - stdw) / stdw * 100; printf("あなたの肥満度は%.1fです.\n", f); return EXIT_SUCCESS; } ---2.2--- #include #include int main(void) { int a, b, c, m, w; printf("三つの整数を入力して下さい:"); scanf("%d%d%d", &a, &b, &c); if (a < b) { w = a; a = b; b = w; } /* ※:a≧b */ if (b > c) m = b; else if (a > c) m = c; else m = a; printf("中間の値は%dです.\n", m); return EXIT_SUCCESS; } ---2.3--- #include #include #include int main(void) { double a, b, c; printf("三つの実数を入力して下さい:"); scanf("%lf%lf%lf", &a, &b, &c); if (a + b > c && c > fabs(a - b)) { double s = (a + b + c) / 2.0; printf("三角形の面積は%.2fです.\n", sqrt(s * (s - a) * (s - b) * (s - c))); } else printf("三角形になりません.\n"); return EXIT_SUCCESS; } ---2.4--- #include #include #include int main(void) { const double eps = 1e-10; double b, c, d, sqd, alpha; printf("係数を入力して下さい:"); scanf("%lf%lf", &b, &c); d = b * b - 4.0 * c; if (fabs(d) < eps) printf("重根:%f\n", -b / 2.0); else { sqd = sqrt(fabs(d)); if (d > 0) { if (b > 0) alpha = (-b - sqd) / 2.0; else alpha = (-b + sqd) / 2.0; printf("二実根:%f, %f\n", alpha, c / alpha); } else printf("二虚根:%f ± %f i\n", -b / 2.0, sqd / 2.0); } return EXIT_SUCCESS; } ---2.5--- #include #include int main(void) { int y, m, d, c, b, dw; printf("年月日を入力して下さい:"); scanf("%d%d%d", &y, &m, &d); m -= 2; if (m < 1) { m += 12; y--; } c = y / 100; b = y % 100; dw = ((26 * m - 2) / 10 + d + b + b / 4 + 5 * c + c / 4) % 7; switch (dw) { case 0: printf("日曜\n"); break; case 1: printf("月曜\n"); break; case 2: printf("火曜\n"); break; case 3: printf("水曜\n"); break; case 4: printf("木曜\n"); break; case 5: printf("金曜\n"); break; case 6: printf("土曜\n"); break; } return EXIT_SUCCESS; }