?? 王大剛--c語言編程寶典--l.htm
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0038)http://www.hjflying.8u8.com/cl/030.htm -->
<HTML><HEAD><TITLE>王大剛-->C語言編程寶典-->L</TITLE>
<META http-equiv=Content-Type content="text/html; charset=GB2312">
<META content="王大剛 C語言編程寶典 L" name=keywords>
<META content="王大剛 - C語言編程寶典 - L" name=description>
<STYLE>#page {
LEFT: 0px; POSITION: absolute; TOP: 0px
}
.tt3 {
FONT: 9pt/12pt "宋體"
}
.tt2 {
FONT: 12pt/15pt "宋體"
}
A {
TEXT-DECORATION: none
}
A:hover {
COLOR: blue; TEXT-DECORATION: underline
}
</STYLE>
<META content="MSHTML 6.00.2600.0" name=GENERATOR></HEAD>
<BODY text=#000000 vLink=#006699 aLink=#9900ff link=#006699 bgColor=#ffffff
leftMargin=3 topMargin=3 marginwidth="3" marginheight="3">
<TABLE cellSpacing=0 cellPadding=10 width="100%" border=0>
<TBODY>
<TR>
<TD class=tt3 vAlign=top width="8%" bgColor=#e0e0e0><STRONG><A
href="http://www.hjflying.8u8.com/cl/031.htm">后一頁</A><BR><A
href="http://www.hjflying.8u8.com/cl/029.htm">前一頁</A><BR><A
href="http://www.hjflying.8u8.com/cl/index.html">回目錄</A><BR><A
href="http://www.hjflying.8u8.com/index.htm">回首頁</A><BR></STRONG></TD>
<TD class=tt2 width="84%" bgColor=#f5f8f8>
<CENTER><B><FONT style="FONT-SIZE: 16.5pt" face=楷體_GB2312
color=#ff6666>L</FONT></B></CENTER>
<HR width="94%" color=#ee9b73 SIZE=1>
<P>函數名: labs <BR>功 能: 取長整型絕對值 <BR>用 法: long labs(long n);
<BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <math.h> <BR>
<P>int main(void) <BR>{ <BR> long result; <BR>
long x = -12345678L; <BR>
<P> result= labs(x); <BR> printf("number: %ld abs
value: %ld\n", <BR> x, result); <BR>
<P> return 0; <BR>} <BR> <BR> <BR> <BR>
<P>函數名: ldexp <BR>功 能: 計算value*2的冪 <BR>用 法: double
ldexp(double value, int exp); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <math.h> <BR>
<P>int main(void) <BR>{ <BR> double value; <BR>
double x = 2; <BR>
<P> /* ldexp raises 2 by a power of 3
<BR> then multiplies the result by
2 */ <BR> value = ldexp(x,3); <BR>
printf("The ldexp value is: %lf\n", <BR>
value); <BR>
<P> return 0; <BR>} <BR> <BR> <BR>
<P>函數名: ldiv <BR>功 能: 兩個長整型數相除, 返回商和余數 <BR>用 法: ldiv_t
ldiv(long lnumer, long ldenom); <BR>程序例: <BR>
<P>/* ldiv example */ <BR>
<P>#include <stdlib.h> <BR>#include <stdio.h> <BR>
<P>int main(void) <BR>{ <BR> ldiv_t lx; <BR>
<P> lx = ldiv(100000L, 30000L); <BR>
printf("100000 div 30000 = %ld remainder %ld\n", lx.quot, lx.rem);
<BR> return 0; <BR>} <BR> <BR> <BR> <BR>
<P>函數名: lfind <BR>功 能: 執行線性搜索 <BR>用 法: void *lfind(void *key,
void *base, int *nelem, int width, <BR> int
(*fcmp)()); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <stdlib.h> <BR>
<P>int compare(int *x, int *y) <BR>{ <BR> return( *x - *y );
<BR>} <BR>
<P>int main(void) <BR>{ <BR> int array[5] = {35, 87, 46, 99,
12}; <BR> size_t nelem = 5; <BR> int key;
<BR> int *result; <BR>
<P> key = 99; <BR> result = lfind(&key, array,
&nelem, <BR> sizeof(int),
(int(*)(const void *,const void *))compare); <BR> if (result)
<BR> printf("Number %d found\n",key);
<BR> else <BR> printf("Number %d
not found\n",key); <BR>
<P> return 0; <BR>} <BR> <BR> <BR>
<P>函數名: line <BR>功 能: 在指定兩點間畫一直線 <BR>用 法: void far line(int
x0, int y0, int x1, int y1); <BR>程序例: <BR>
<P>#include <graphics.h> <BR>#include <stdlib.h> <BR>#include
<stdio.h> <BR>#include <conio.h> <BR>
<P>int main(void) <BR>{ <BR> /* request auto detection */
<BR> int gdriver = DETECT, gmode, errorcode; <BR>
int xmax, ymax; <BR>
<P> /* initialize graphics and local variables */
<BR> initgraph(&gdriver, &gmode, ""); <BR>
<P> /* read result of initialization */ <BR>
errorcode = graphresult(); <BR> /* an error occurred */
<BR> if (errorcode != grOk) <BR> {
<BR> printf("Graphics error: %s\n",
<BR>
grapherrormsg(errorcode)); <BR>
printf("Press any key to halt:"); <BR>
getch(); <BR> exit(1); <BR> }
<BR>
<P> setcolor(getmaxcolor()); <BR> xmax =
getmaxx(); <BR> ymax = getmaxy(); <BR>
<P> /* draw a diagonal line */ <BR> line(0, 0,
xmax, ymax); <BR>
<P> /* clean up */ <BR> getch(); <BR>
closegraph(); <BR> return 0; <BR>} <BR> <BR> <BR>
<P>函數名: linerel <BR>功 能: 從當前位置點(CP)到與CP有一給定相對距離的點畫一直線 <BR>用 法:
void far linerel(int dx, int dy); <BR>程序例: <BR>
<P>#include <graphics.h> <BR>#include <stdlib.h> <BR>#include
<stdio.h> <BR>#include <conio.h> <BR>
<P>int main(void) <BR>{ <BR> /* request auto detection */
<BR> int gdriver = DETECT, gmode, errorcode; <BR>
char msg[80]; <BR>
<P> /* initialize graphics and local variables */
<BR> initgraph(&gdriver, &gmode, ""); <BR>
<P> /* read result of initialization */ <BR>
errorcode = graphresult(); <BR> if (errorcode != grOk)
<BR> { <BR> printf("Graphics
error: %s\n", <BR> grapherrormsg(errorcode));
<BR> printf("Press any key to halt:");
<BR> getch();
<BR> exit(1); <BR> } <BR>
<P> /* move the C.P. to location (20, 30) */ <BR>
moveto(20, 30); <BR>
<P> /* create and output a <BR>
message at (20, 30) */ <BR> sprintf(msg, " (%d, %d)", getx(),
gety()); <BR> outtextxy(20, 30, msg); <BR>
<P> /* draw a line to a point a relative
<BR> distance away from the current
<BR> value of C.P. */
<BR> linerel(100, 100); <BR>
<P> /* create and output a message at C.P. */ <BR>
sprintf(msg, " (%d, %d)", getx(), gety()); <BR> outtext(msg);
<BR>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -