数模论坛

 找回密码
 注-册-帐-号
搜索
热搜: 活动 交友 discuz

C语言的函数!

  [复制链接]
 楼主| 发表于 2004-5-8 17:11:20 | 显示全部楼层
<>函数名: assert
功  能: 测试一个条件并可能使程序终止
用  法: void assert(int test);
程序例:
#include &lt;assert.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt; <>struct ITEM {
   int key;
   int value;
}; <>/* add item to list, make sure list is not null */
void additem(struct ITEM *itemptr) {
   assert(itemptr != NULL);
   /* add item to list */
} <P>int main(void)
{
   additem(NULL);
   return 0;
}
  
  
  </P>
 楼主| 发表于 2004-5-8 17:11:37 | 显示全部楼层
<>函数名: atan
功  能: 反正切函数
用  法: double atan(double x);
程序例:
#include &lt;stdio.h&gt;
#include &lt;math.h&gt; <>int main(void)
{
   double result;
   double x = 0.5; <>   result = atan(x);
   printf("The arc tangent of %lf is %lf\n", x, result);
   return(0);
}
  
  </P>
 楼主| 发表于 2004-5-8 17:11:51 | 显示全部楼层
<>函数名: atan2
功  能: 计算Y/X的反正切值
用  法: double atan2(double y, double x);
程序例:
#include &lt;stdio.h&gt;
#include &lt;math.h&gt; <>int main(void)
{
   double result;
   double x = 90.0, y = 45.0; <>   result = atan2(y, x);
   printf("The arc tangent ratio of %lf is %lf\n", (y / x), result);
   return 0;
}
  
  </P>
 楼主| 发表于 2004-5-8 17:12:16 | 显示全部楼层
<>函数名: atexit
功  能: 注册终止函数
用  法: int atexit(atexit_t func);
程序例:
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt; <>void exit_fn1(void)
{
   printf("Exit function #1 called\n");
} <>void exit_fn2(void)
{
   printf("Exit function #2 called\n");
} <P>int main(void)
{
   /* post exit function #1 */
   atexit(exit_fn1);
   /* post exit function #2 */
   atexit(exit_fn2);
   return 0;
}
  
  
  </P>
 楼主| 发表于 2004-5-8 17:12:32 | 显示全部楼层
<>函数名: atof
功  能: 把字符串转换成浮点数
用  法: double atof(const char *nptr);
程序例:
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt; <>int main(void)
{
   float f;
   char *str = "12345.67"; <>   f = atof(str);
   printf("string = %s float = %f\n", str, f);
   return 0;
}
  
  </P>
 楼主| 发表于 2004-5-8 17:12:51 | 显示全部楼层
<>函数名: atoi
功  能: 把字符串转换成长整型数
用  法: int atoi(const char *nptr);
程序例:
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt; <>int main(void)
{
   int n;
   char *str = "12345.67"; <>   n = atoi(str);
   printf("string = %s integer = %d\n", str, n);
   return 0;
}
  
  </P>
 楼主| 发表于 2004-5-8 17:13:03 | 显示全部楼层
<>函数名: atol
功  能: 把字符串转换成长整型数
用  法: long atol(const char *nptr);
程序例: <>#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt; <>int main(void)
{
   long l;
   char *str = "98765432"; <P>   l = atol(lstr);
   printf("string = %s integer = %ld\n", str, l);
   return(0);
}
  </P>
 楼主| 发表于 2004-5-8 17:13:53 | 显示全部楼层
<>函数名: bar
功  能: 画一个二维条形图
用  法: void far bar(int left, int top, int right, int bottom);
程序例: <>#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, i; <P>   /* initialize graphics and local variables */
   initgraph(&amp;gdriver, &amp;gmode, ""); <P>   /* read result of initialization */
   errorcode = graphresult();
   if (errorcode != grOk)  /* an error occurred */
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1); /* terminate with an error code */
   } <P>   midx = getmaxx() / 2;
   midy = getmaxy() / 2; <P>   /* loop through the fill patterns */
   for (i=SOLID_FILL; i&lt;USER_FILL; i++)
   {
      /* set the fill style */
      setfillstyle(i, getmaxcolor()); <P>      /* draw the bar */
      bar(midx-50, midy-50, midx+50,
         midy+50); <P>      getch();
   } <P>   /* clean up */
   closegraph();
   return 0;
}
  
  
  </P>
 楼主| 发表于 2004-5-8 17:14:10 | 显示全部楼层
<>函数名: bar3d
功  能: 画一个三维条形图
用  法: void far bar3d(int left, int top, int right, int bottom,
                       int depth, int topflag);
程序例: <>#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, i; <P>   /* initialize graphics, local variables */
   initgraph(&amp;gdriver, &amp;gmode, ""); <P>   /* read result of initialization */
   errorcode = graphresult();
   if (errorcode != grOk)  /* an error occurred */
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1); /* terminate with error code */
   } <P>   midx = getmaxx() / 2;
   midy = getmaxy() / 2; <P>   /* loop through the fill patterns */
   for (i=EMPTY_FILL; i&lt;USER_FILL; i++)
   {
      /* set the fill style */
      setfillstyle(i, getmaxcolor()); <P>      /* draw the 3-d bar */
      bar3d(midx-50, midy-50, midx+50, midy+50, 10, 1); <P>      getch();
   } <P>   /* clean up */
   closegraph();
   return 0;
}
  
  
  </P>
 楼主| 发表于 2004-5-8 17:14:25 | 显示全部楼层
<>函数名: bdos
功  能: DOS系统调用
用  法: int bdos(int dosfun, unsigned dosdx, unsigned dosal);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;dos.h&gt; <>/* Get current drive as 'A', 'B', ... */
char current_drive(void)
{
   char curdrive; <P>   /* Get current disk as 0, 1, ... */
   curdrive = bdos(0x19, 0, 0);
   return('A' + curdrive);
} <P>int main(void)
{
   printf("The current drive is %c:\n", current_drive());
   return 0;
}
  
  
  </P>
您需要登录后才可以回帖 登录 | 注-册-帐-号

本版积分规则

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

GMT+8, 2024-3-19 16:09 , Processed in 0.051333 second(s), 12 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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