遮蔽参数 [英] shadowing a parameter

查看:122
本文介绍了遮蔽参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编写一个计算函数积分的程序


f(x)=(A * x ^ m)/ n!


从a到b的间隔(0
a为m的双值和n的非负整数值,

a的双值,a和b的正双值> a。

调用函数Intgr()来评估积分。


你的主程序应该有三个函数:

double Intgr(double m,int n,double A,double a,double b)


double func(double x,double m,int n,double A)


double nfact(int n)


编写函数Intgr()时,使用程序w4-10.c

或来自你的hw5的B部分的程序,经过适当的修改

来整合任意函数f(x)从a到b

(让程序只询问你一次n_trap,并扫描

n_trap的足够大的值。在Intgr()中调用另一个

函数func()来指定f(x)。如果n = 0,或者A * x ^ m / n,则func()的返回值应该等于A * x ^ m!如果n> 0。评估n!调用你也要写的

函数nfact()。要评估x ^ m调用

函数pow()已嵌入math.h库中。


.......... ........................................ .......... ....


您的输出应如下所示:

在f中输入指数(double)m和(int)n( X)= A * X ^ M / N! :3.25 5

输入f(x)中的系数A = A * x ^ m / n! :-1.5


输入积分间隔的边界,a< b:1.5 3.75


在[a,b]上整合f(x)

输入梯形数:1000


积分的值是-0.792905。


* /

Write a program which calculates the integral of the function

f(x)=(A*x^m)/n!

on the interval from a to b (0<a<b). In the main program, scanf
a double value for m and a non-negative integer value for n,
a double value of A, and positive double values for a and b>a.
Call the function Intgr() to evaluate the integral.

Your main program should be followed by three functions:

double Intgr(double m, int n, double A, double a, double b)

double func(double x, double m, int n, double A)

double nfact(int n)


When writing the function Intgr(), use the program w4-10.c
or the program from part B of your hw5, appropriately modified
to integrate an arbitrary function f(x) from a to b
(let the program ask you for n_trap only once, and scan
sufficiently large value for n_trap). Within Intgr() call another
function func() to specify f(x). The return value of func() should
be equal to A*x^m if n=0, or A*x^m/n! if n>0. To evaluate n! call the
function nfact() that you will also write. To evaluate x^m call
the function pow() already embedded in the math.h library.

.................................................. ..............

Your output should look like this:

Enter the exponents (double)m and (int)n in f(x)=A*x^m/n! : 3.25 5

Enter the coefficient A in f(x)=A*x^m/n! : -1.5

Enter the bounds for the integration interval, a < b : 1.5 3.75

Integrate f(x) on [a,b]
Enter the number of trapezoids: 1000

The value of the integral is -0.792905 .

*/

展开 | 选择 | 换行 | 行号

推荐答案

首先,在double func()中,您需要在传递它的最后两个变量之间使用逗号。我也不认为你应该重新宣布你传给它的金额。


这与Intgr()是一样的,从那里你应该能够从输出语句调试(降低到大约15,但它们看起来很容易管理 - 但是如果你开始遇到问题就告诉我们)。
First of all, in double func() you need a comma between the last two variables you are passing it. I also don''t think you should be redeclaring the amounts you are passing to it.

It''s the same thing with Intgr() and from there, you should be able to debug from the output statements (gets you down to about 15, but they look manageable at first glance - but let us know if you start having trouble with them).


这是你的代码更正了!

注意重新声明没有必要!

PS:不要注意你将拥有的3个警告! ;)
this is ur code corrected!
pay attention to redeclaration NO NEED!
PS: dont pay attention to the 3 warnings that u will have! ;)
展开 | 选择 | Wrap | 行号


下次提及你的编译器!

thx!
plz mention ur compiler next time !
thx!


这篇关于遮蔽参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆