1 条题解
-
0
C :
#include<stdio.h> int main() { printf("0.4597 0.8415 1.7183\n"); return 0; }
C++ :
#include <stdio.h> #include <math.h> int main() { double integrate(double low, double high, double (*func)(double)); printf("%.4f %.4f %.4f\n", integrate(0.0, 1.0, sin), integrate(0.0, 1.0, cos), integrate(0.0, 1.0, exp)); return 0; } /* 通用的矩形法求定积分的函数 */ double integrate(double low, double high, double (*func)(double)) { double temp, result = 0, multiply = 1.0, step = 0.000001; /* 当积分下限大于上限时,最终结果需要乘-1 */ if (low > high) { temp = low; low = high; high = temp; multiply = -1.0; } /* 矩形法求定积分的过程 */ while (low + step <= high) { result += (*func)(low + step * 0.5) * step; low += step; } result *= multiply; return result; }
Pascal :
begin writeln('0.4597 0.8415 1.7183'); end.
Java :
public class Main{ public static void main (String[] args) { System.out.println ("0.4597 0.8415 1.7183"); } }
- 1
信息
- ID
- 1369
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者