数模论坛

 找回密码
 注-册-帐-号
搜索
热搜: 活动 交友 discuz
查看: 750610|回复: 589

C语言的函数!

  [复制链接]
发表于 2004-5-8 17:08:04 | 显示全部楼层 |阅读模式
游客,如果您要查看本帖隐藏内容请回复

[此贴子已经被作者于2004-5-10 9:01:54编辑过]

发表于 2004-5-10 03:39:44 | 显示全部楼层
<>没有意思,贴的都是大家知道的。把个人心得贴出多好。</P>
 楼主| 发表于 2004-5-8 17:08:24 | 显示全部楼层
<>函数名: abs
功  能: 求整数的绝对值
用  法: int abs(int i);
程序例:
#include &lt;stdio.h&gt;
#include &lt;math.h&gt; <>int main(void)
{
  int number = -1234; <>  printf("number: %d  absolute value: %d\n", number, abs(number));
  return 0;
}
  
  </P>
 楼主| 发表于 2004-5-8 17:08:45 | 显示全部楼层
<>函数名: absread, abswirte
功  能: 绝对磁盘扇区读、写数据
用  法: int absread(int drive, int nsects, int sectno, void *buffer);
int abswrite(int drive, int nsects, in tsectno, void *buffer);
程序例:
/* absread example */ <>#include &lt;stdio.h&gt;
#include &lt;conio.h&gt;
#include &lt;process.h&gt;
#include &lt;dos.h&gt; <>int main(void)
{
  int i, strt, ch_out, sector;
  char buf[512]; <P>  printf("Insert a diskette into drive A and press any key\n");
  getch();
  sector = 0;
  if (absread(0, 1, sector, &amp;buf) != 0)
  {
     perror("Disk problem");
     exit(1);
  }
  printf("Read OK\n");
  strt = 3;
  for (i=0; i&lt;80; i++)
  {
     ch_out = buf[strt+i];
     putchar(ch_out);
  }
  printf("\n");
  return(0);
}
  
  
  </P>
 楼主| 发表于 2004-5-8 17:09:12 | 显示全部楼层
<>函数名: access
功  能: 确定文件的访问权限
用  法: int access(const char *filename, int amode);
程序例:
#include &lt;stdio.h&gt;
#include &lt;io.h&gt; <>int file_exists(char *filename); <>int main(void)
{
  printf("Does NOTEXIST.FIL exist: %s\n",
  file_exists("NOTEXISTS.FIL") ? "YES" : "NO");
  return 0;
} <P>int file_exists(char *filename)
{
  return (access(filename, 0) == 0);
}
  </P>
 楼主| 发表于 2004-5-8 17:09:28 | 显示全部楼层
<>函数名: acos
功  能: 反余弦函数
用  法: double acos(double x);
程序例:
#include &lt;stdio.h&gt;
#include &lt;math.h&gt; <>int main(void)
{
  double result;
  double x = 0.5; <>  result = acos(x);
  printf("The arc cosine of %lf is %lf\n", x, result);
  return 0;
}
  
  </P>
 楼主| 发表于 2004-5-8 17:10:11 | 显示全部楼层
<>函数名: allocmem
功  能: 分配DOS存储段
用  法: int allocmem(unsigned size, unsigned *seg);
程序例:
#include &lt;dos.h&gt;
#include &lt;alloc.h&gt;
#include &lt;stdio.h&gt; <>int main(void)
{
  unsigned int size, segp;
  int stat; <>  size = 64; /* (64 x 16) = 1024 bytes */
  stat = allocmem(size, &amp;segp);
  if (stat == -1)
     printf("Allocated memory at segment: %x\n", segp);
  else
     printf("Failed: maximum number of paragraphs available is %u\n",
            stat); <P>  return 0;
}
  
  </P>
 楼主| 发表于 2004-5-8 17:10:32 | 显示全部楼层
<>函数名: arc
功  能: 画一弧线
用  法: void far arc(int x, int y, int stangle, int endangle, int radius);
程序例:
#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt; <>int main(void)
{
    /* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   int midx, midy;
   int stangle = 45, endangle = 135;
   int radius = 100; <>   /* initialize graphics and local variables */
   initgraph(&amp;gdriver, &amp;gmode, ""); <P>   /* read result of initialization */
   errorcode = graphresult();    /* an error occurred */
   if (errorcode != grOk)
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch(); <P>      exit(1);    /* terminate with an error code */
   } <P>   midx = getmaxx() / 2;
   midy = getmaxy() / 2;
   setcolor(getmaxcolor()); <P>   /* draw arc */
   arc(midx, midy, stangle, endangle, radius); <P>   /* clean up */
   getch();
   closegraph();
   return 0;
}
  
  </P>
 楼主| 发表于 2004-5-8 17:10:49 | 显示全部楼层
<>函数名: asctime
功  能: 转换日期和时间为ASCII码
用  法: char *asctime(const struct tm *tblock);
程序例:
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;time.h&gt; <>int main(void)
{
   struct tm t;
   char str[80]; <>   /* sample loading of tm structure  */ <P>   t.tm_sec    = 1;  /* Seconds */
   t.tm_min    = 30; /* Minutes */
   t.tm_hour   = 9;  /* Hour */
   t.tm_mday   = 22; /* Day of the Month  */
   t.tm_mon    = 11; /* Month */
   t.tm_year   = 56; /* Year - does not include century */
   t.tm_wday   = 4;  /* Day of the week  */
   t.tm_yday   = 0;  /* Does not show in asctime  */
   t.tm_isdst  = 0;  /* Is Daylight SavTime; does not show in asctime */ <P>   /* converts structure to null terminated
   string */ <P>   strcpy(str, asctime(&amp;t));
   printf("%s\n", str); <P>   return 0;
}
  
  
  </P>
 楼主| 发表于 2004-5-8 17:11:05 | 显示全部楼层
<>函数名: asin
功  能: 反正弦函数
用  法: double asin(double x);
程序例:
#include &lt;stdio.h&gt;
#include &lt;math.h&gt; <>int main(void)
{
   double result;
   double x = 0.5; <>   result = asin(x);
   printf("The arc sin of %lf is %lf\n", x, result);
   return(0);
}
  
  
  </P>
您需要登录后才可以回帖 登录 | 注-册-帐-号

本版积分规则

小黑屋|手机版|Archiver|数学建模网 ( 湘ICP备11011602号 )

GMT+8, 2024-3-19 10:38 , Processed in 0.054673 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表