| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 547 人关注过本帖
标题:请教几个用法
只看楼主 加入收藏
Areik
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2009-9-28
结帖率:87.5%
收藏
已结贴  问题点数:10 回复次数:7 
请教几个用法
这是今天上课遇到的一个程序,有些东西不大了解。。。。

#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);
           }

     printf("The Sin(x) is: %lf\n",sin(dx));

     I=1;
     dTemp =Term(dx, I);
     dSin=0;

     while(fabs(dTemp)>=dEps)
          {
              Sin=dSin+dTemp;
              I=I+1;
              dTemp=Term(x,I);
           }

     printf("Sin x is: %lf\n",Sin);

     if(fabs(dTemp)<dEps)
         printf("Looping stop at Term(%d) = %lf",I,dTemp);

     printf("\n");

     return 0;
}


double Factorial(int J)
{
       int Z;
       double Fac=1;

       for(Z=1; Z<=J; Z++)
          {
              Fac=Fac*Z;
           }
       return (Fac);
}

double Term(double dx, int I)
{
       int J=(2*I)-1;
       double dTemp;
       dTemp = (pow(dx,J))/Factorial(J);
       if ((I%2)==0)
           dTemp=-1*dTemp;
       printf("I=%d J=%d Temp=%lf\n",I,J,dTemp);

       return(dTemp);
}


1.在内int main之前的两个定义double factorial(int);   double Term(double, int);是啥意思?

2.scanf("%lf",&dEps);中%后面的l是什么意思?

3.if(fabs(dTemp)<dEps)这个条件中的fabs指的什么?

4.double Factorial(int J)和double Term(double dx, int I)定义是什么意思?

希望前辈能解释一下。。。谢谢
搜索更多相关主题的帖子: 用法 
2009-10-29 00:59
cosdos
Rank: 9Rank: 9Rank: 9
来 自:ShangHai
等 级:蜘蛛侠
威 望:6
帖 子:2109
专家分:1385
注 册:2007-6-19
收藏
得分:5 
1. 函数声明,必须在使用函数前声明函数。(你必须遵守,即使是TC。C语言标准要求这样做)

2. double 类型使用 %lf

3.   数学函数:fabs
     原型:float fabs(float x);
     用法:#include <math.h>
     功能:求浮点数x的绝对值

—>〉Sun〈<—
2009-10-29 01:04
cosdos
Rank: 9Rank: 9Rank: 9
来 自:ShangHai
等 级:蜘蛛侠
威 望:6
帖 子:2109
专家分:1385
注 册:2007-6-19
收藏
得分:0 
C99 标准还规定了,函数不接受参数必须使用 void。

int main(void)
{
    return 0;
}

C++ 标准中,void是可选的。

—>〉Sun〈<—
2009-10-29 01:08
chiZ
Rank: 2
来 自:paradise
等 级:论坛游民
帖 子:27
专家分:99
注 册:2009-10-25
收藏
得分:5 
1. it is proptype. when you want to call a function after main, you have to write propotype before main. if you don't write this, compiler does not know what these functions are. by the way, if you write your main at the end of program, you don't have to write proptype.
2.%f is for floating point. %lf is for double
3.fabs is a function in libriary math.h.its job is to return absolute value of your input. for your example, it is going to compare absolute value of dTemp with dEps.
4.double Factorial(int J) is J!. this means that 4! = 4*3*2*1 =24 . 4 is your in put J. 24 is your return value.
  term function is to find dx^(2I-1)/(2I-1)!. if this value is even, then return its opposite value.if it is odd,then return it directly.
2009-10-29 02:27
rengang2005
Rank: 2
等 级:论坛游民
帖 子:23
专家分:57
注 册:2006-10-20
收藏
得分:0 
回复 4楼
为什么你总是用英语?可能会让发帖人看不明白?

[ 本帖最后由 rengang2005 于 2009-10-29 13:50 编辑 ]
2009-10-29 13:48
chiZ
Rank: 2
来 自:paradise
等 级:论坛游民
帖 子:27
专家分:99
注 册:2009-10-25
收藏
得分:0 
回复 5楼 rengang2005
呵呵!!编程的一些语言我中文不知道怎么说!
2009-10-29 15:04
pgy
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:C
等 级:小飞侠
威 望:8
帖 子:1248
专家分:2329
注 册:2009-9-23
收藏
得分:0 
回复 5楼 rengang2005
因为4楼来自天堂
    神仙的语言凡人岂能轻易明白
        so,We should strive to learn English, so as to better learning C language

我可好玩啦...不信你玩玩^_^
2009-10-29 15:13
Areik
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2009-9-28
收藏
得分:0 
回复各位:谢谢你们的帮助

To fourth floor: Thanks for your help.
2009-10-30 00:24
快速回复:请教几个用法
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012579 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved