谁能给我解释一个程序里某些语句的用法?

来源:百度知道 编辑:UC知道 时间:2024/05/29 22:41:34
原题:Write a program, that after the entering of a real number x and a real number eps (the accuracy) computes
the value for sin_x (until |Term(n)|<eps complies) , using factoring over n terms.
Print x, sin_x, sin(x) and the n-th term. Use functions Fac() and Term() according to:

sin_x = Term1 + Term2 + Term3 + … = x - x3/3! + x5/5! - x7/7! + …. [ example: Fac(3) = 1.2.3 ]

#include <stdio.h>
#include <math.h>
#include <conio.h>

double factorial(int);
double Term(double, int);

int main()
{ int I;
double dTemp, dEps, dx, dSin;

printf("Please enter a value of x:");
scanf("%lf",&dEps);
printf("Enter the accuracy value: ");
scanf("%lf",&dx);

while (dEps<=0)
{
printf("Input wrong! Enter Eps:");
scanf("%lf",&dEps);
}

很简单的问题,其实只要好好看完谭老的书,这些问题就不在是问题了。加油吧。
1.这两个是对函数的声明,double factorial(int) double 是函数的返回值类型, int是函数参数的类型,这里只有一个参数。另外一个也是这个意思。不过Term函数的参数是有两个参数,double类型和int类型。因为程序中有对自定义函数的引用,所以首先要进行声明,程序的最后则是对这两个函数的定义。
2.l是long的意思,明白了吧,就是长类型,如long int,就是长整型。这里lf就是双精度。
3.fabs是编译器提供的函数,求绝对值。就是求dTemp的绝对值然后与dEps进行比较。
4.这个我已经说了,程序的最后是对所自定义的函数进行的定义。也就是对你自己定义的函数的设计。
通过你提的问题可以看出,对c的学习还是很浅。书本的基本知识还是要抓经的,毕竟没有基本功,想学好c语言是不可能的。
建议你先看完谭浩强的c语言教程。
加油!!

/* 文件包含 */
#include <stdio.h>
#include <math.h>
#include <conio.h>

/* 函数声明 */
double factorial(int); /* 声明一个函数名为factorial,函数参数为int型的函数 */
double Term(double, int); /* 同上 */

int main(void)
{
int I; /* 定义整型变量I */
double dTemp, dEps, dx, dSin; /* 定义双精度浮点数 */

printf("Please enter a value of x:");
scanf("%lf",&dEps); /* %lf 指输入双精度浮点数 */
printf("Enter the accuracy value: ");