|
|
发表于 2005-12-24 10:40:07| 字数 1,246| - 中国–湖北–武汉 电信
|
显示全部楼层
|阅读模式
MM有两道C的试题不会做,找偶,可偶的C都还给老师N多年了,没法,只有求助这里的各位XD了.
多谢.
[程序说明] 该程序用于计算cos x值,依据公式为:
要求输入X(以角度计)和误差值epsil。当epsil<=0时程序停止执行。
#include
#define PI 3.141526
double ex(x,epsil)
float x,epsil;
{
double t,s; int n;
s=0.0; t=1.0; n=1;
while ((t>=0.0?t:-t)>epsil){
s+=t;___(1)___;___(2)___;
}
return s;
}
main()
{
float x,epsil;
printf("Input x,epsil epsil<=0 to quit)\n");
scanf("%f%f",&x,&epsil);
while(epsil>0.0){
x*=PI/180;
printf("e^%f=%f\n",x,ex(x,epsil));
printf("Input x,epsil epsil<=0 to quit)\n");
scanf("%f%f",&x,&epsil);
}
}
[程序说明]该程序能计算两个整数集合A与B的差,其中A与B的元素都以值的递增次序存放中单链表中,A中的同一元素允许在单链表中出现多次,A与B的差也以值的递增次序存于单链表内,但是同一元素不允许出现多次。假定调用diff前a,b的值已创建。
#include
typedef struct node{
int d;
struct node *next;
}tnode;
void diff(a,b,c)
tnode *a,*b,__(1)__;
{
int last_a; tnode *p;
*c=NULL; last_a=-9999;
while(a&&b){
if(a->d==b->d){
__(2)__;
a=a->next;
__(3)__;
}
else
if (a->d>d->d)
__(4)__;
else {
if (a->d!=last_a){
last_a=a->d;
p=(tnode *)malloc(sizeof(tnode));
p->d=last_a;
p->next=*c;
*c=p;
}
a=a->next;
}
}
while(a){
if(__(5)__){
last_a=a->d;
p->d=last_a;
p->next=*c;
__(6)__;
}
a=a->next;
}
}
void print(h)
tnode *h;
{
while(h){
printf("%d ",h->d);
h=h->next;
}
}
main()
{
tnode *a,*b,*c;
...
diff(a,b,&c);
print(c);
} |
|