找回密码
 注册
快捷导航
查看: 426|回复: 0

【求助】有熟悉C语言的大侠请进

 关闭 [复制链接] |自动提醒
阅读字号:

288

回帖

4

积分

2209

资产值

高级会员 Rank: 2Rank: 2

注册时间
2003-7-16
铜牌荣誉勋章(注册8年以上会员)
发表于 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,epsilepsil<=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,epsilepsil<=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);
  }
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Powered by Discuz! X3.5 © 2001-2023 Comsenz Inc

GMT+8, 2025-10-24 16:26 , Processed in 0.065839 second(s), 25 queries , Gzip On, OPcache On.

手机版|小黑屋|安卓客户端|iOS客户端|Archiver|备用网址1|备用网址2|在线留言|专门网

返回顶部