#include <stdio.h>
#include <math.h>
int main()
{ float fun(float a、float b、float(* p)(float、float)); float fun1(float、float); float fun2(float、float); float fun3(float、float); float fun4(float、float); float fun5(float、float); int n; printf( "1から5までの数の関数を入力してください:\ n"); scanf_s( "%d"、&n); スイッチ(n) { case 1:printf( "this is the first function、"); fun(1、4、fun1); ブレーク; ケース2:printf( "これは2番目の関数です。"); fun(1、4、fun2); ブレーク;
ケース3:printf( "これは3番目の関数です。");
fun(1、4、fun3);
ブレーク;
ケース4:printf( "これは4番目の関数です。");
fun(1、4、fun4);
ブレーク;
ケース5:printf( "これは5番目の関数です。");
fun(1、4、fun5);
ブレーク;
デフォルト:printf( "DATA ERROR");
}
0を返します。
}
float fun(float x、float y、float(* p)(float、float))
{ float結果; 結果=(* p)(x、y); printf( "関数の統合は%8.2f \ n"、結果); } float fun1(float a、float b){ float sum;
合計= b + 0.5 * b * b-a-0.5 * a * a;
合計を返す;
}
float fun2(float a、float b)
{ float sum; 合計= b * b + 3 * b-a * a-3 * a; 合計を返す; } float fun3(float a、float b) { float sum; sum = exp(b)+ b-exp(a)-a; 合計を返す; } float fun4(float a、float b){ float sum; 合計=(1.0 / 3.0)*(pow((1 + b)、3))-(1.0 / 3.0)*(pow((1 + a)、3)); 合計を返す; } float fun5(float a、float b){ float sum; 合計=(1.0 / 4.0)* pow(b、4)-(1.0 / 4.0)* pow(a、4);
合計を返す;
}
ポインター変数を使用して、彼が指す関数を呼び出し、定積分を取得します。5つの一般的な関数がリストされています。コードは次のとおりです。
おすすめ
転載: blog.csdn.net/progess_every_day/article/details/104860316
おすすめ
ランキング