示例程序:#include stdio.h#include math.h#define EPSILON 1e-6double f(double x) {return 2 * pow(x, 3) - 4 * pow(x, 2) + 3 * x - 6;}double f_prime(double x) {return 6 * pow(x, 2) - 8 * x + 3;}...

示例程序:
#include <stdio.h>
#include <math.h>
#define EPSILON 1e-6
double f(double x) {
return 2 * pow(x, 3) - 4 * pow(x, 2) + 3 * x - 6;
}
double f_prime(double x) {
return 6 * pow(x, 2) - 8 * x + 3;
}
double h(double x) {
return pow(x, 3) - 4*pow(x, 2) + 3*x - 6;
}
double h_prime(double x) {
return 3*pow(x,2) - 8*x + 3;
}
double newton(double (*fp)(double), double (*fp_prime)(double)) {
double x = 1.5;
while (fabs(fp(x)) > EPSILON){
x = x - fp(x) / fp_prime(x);
}
return x;
}
int main() {
printf("%g\n", newton(f, f_prime));
printf("%g\n", newton(h, h_prime));
return 0;
}
织梦狗教程
本文标题为:C语言学习笔记 —— 函数作为参数


基础教程推荐
猜你喜欢
- 带你深度走入C语言取整以及4种函数 2022-09-17
- C语言 详解字符串基础 2023-03-27
- [C语言]二叉搜索树 2023-09-07
- 全面了解C语言 static 关键字 2023-03-26
- C语言实现宾馆管理系统课程设计 2023-03-13
- C语言编程C++旋转字符操作串示例详解 2022-11-20
- C++实战之二进制数据处理与封装 2023-05-29
- C++实现ETW进行进程变动监控详解 2023-05-15
- [c语言-函数]不定量参数 2023-09-08
- centos 7 vscode cmake 编译c++工程 2023-09-17