数学建模社区-数学中国

标题: 函数大全(l开头) [打印本页]

作者: 韩冰    时间: 2004-10-4 02:58
标题: 函数大全(l开头)
<><FONT color=#ff0000>函数名: labs </FONT>% f4 b" @1 t* v
用 法: long labs(long n);
2 D+ L5 B2 V6 Z! a$ Y( h程序例: </P>
- S: ^+ K' ]* U: n1 [9 M; P8 |<><FONT color=#0000ff>#include <STDIO.H>
* M3 L5 W# i: [2 O1 J. f- h#include <MATH.H></FONT></P>
* a5 [- Z9 m# g& D6 c! {, E<><FONT color=#0000ff>int main(void)
  v$ [6 C- r. G; X+ d+ E$ ?3 X% N{
% K& G( u; O+ |long result; / g; L* w2 G' v% z2 H
long x = -12345678L; </FONT></P>
: W) Y7 N. t; ~' v' H1 r. Q- p<><FONT color=#0000ff>result= labs(x); 3 @0 B1 ?5 a- o" Z+ C, L
printf("number: %ld abs value: %ld\n", 7 ?' |! L/ s" |. `; G1 h
x, result); </FONT></P>! g! `' l7 @( p& ~0 i" Z: h
<><FONT color=#0000ff>return 0; , s( ?% g1 N  {. t9 }" E6 Q7 z
} 3 j% i+ [7 r$ ^5 u. X, ^2 U( o8 H
</FONT>
" u3 \3 [# Q. {; i
. b1 I; v/ P0 b/ Q' P( y: W% ?</P>  [# O3 i* |5 s" p2 P) p4 ]
<><FONT color=#ff0000>函数名: ldexp </FONT>
6 `% i$ D# n( m" s功 能: 计算value*2的幂 ( A: a8 |# j+ z8 s  y# S
用 法: double ldexp(double value, int exp); ! L; r) k9 o7 ]+ Y3 `4 t; L
程序例: </P>: X+ I- W# X; Y7 w/ B2 w+ \$ p/ J4 H
<><FONT color=#0000ff>#include <STDIO.H># d" a0 K" d9 Q# a
#include <MATH.H></FONT></P>- R" u4 t& g) f% n/ ?) n0 K
<><FONT color=#0000ff>int main(void) ! C3 Z4 q/ d" |* B6 w0 W
{ ; W. T* s- Y( y8 |
double value;
1 i5 V7 O1 w- cdouble x = 2; </FONT></P>
; j4 M' G7 |1 n  W& E9 A<><FONT color=#0000ff>/* ldexp raises 2 by a power of 3
6 l, X2 Z% B3 {! d/ D" Xthen multiplies the result by 2 */
/ M8 }! ]0 j9 U4 E6 K( qvalue = ldexp(x,3); / }8 ?! t) G/ f2 e  G
printf("The ldexp value is: %lf\n", # W' n: Y" [1 C4 T" C) Y7 X" k
value); </FONT></P>
& @3 Y7 a4 l7 ~( F3 L1 t" M<><FONT color=#0000ff>return 0; ' t' F4 L- a" P9 E! o/ c' }6 k$ h
}   u/ f) A! q* I7 H- E/ a, c

' X6 o5 h4 K* k) Z  i</FONT></P>
6 h! |- H+ a0 _<><FONT color=#ff0000>函数名: ldiv </FONT>5 q7 y8 f- W$ }
功 能: 两个长整型数相除, 返回商和余数
7 Q# R% u+ B+ u, r' d用 法: ldiv_t ldiv(long lnumer, long ldenom);
9 Y) h# v) W7 u( n( _# }程序例: </P>
# B# r1 M* d! ?- w) [! c5 f0 Y<><FONT color=#0000ff>/* ldiv example */ </FONT></P>
' Y5 A! [' R' B, N' h- s9 W<><FONT color=#0000ff>#include <STDLIB.H>
/ h1 w' X5 ]2 u# Q7 p$ x#include <STDIO.H></FONT></P>  `% u) ?( Y! T/ D1 }
<><FONT color=#0000ff>int main(void)
+ M) j7 |: H6 j4 j- l{
5 F# P" }) T( u6 eldiv_t lx; </FONT></P>
8 f/ `% c* z+ q0 ?<><FONT color=#0000ff>lx = ldiv(100000L, 30000L); " b! p3 I7 k8 y) n( ~9 y4 T1 A
printf("100000 div 30000 = %ld remainder %ld\n", lx.quot, lx.rem); / I7 U. w- N$ ~5 r: A
return 0; </FONT>
% P& `6 w( A' U. q& x* R<FONT color=#0000ff>} </FONT>" M6 m. h5 z: R
</P>  Y% ^' ^1 G3 y" [8 t' c6 a
<><FONT color=#ff0000>函数名: lfind </FONT>, o* c% s  h. O2 B# R0 a
功 能: 执行线性搜索
) n  P7 N9 O# V用 法: void *lfind(void *key, void *base, int *nelem, int width,
' W4 k: z3 |6 U4 J* d& B3 P# f  Uint (*fcmp)());
4 z; v0 M% c! f% l( e- c程序例: </P>" A! E: a4 g- C7 D2 Y
<><FONT color=#0000ff>#include <STDIO.H>. I+ y. _' Z9 ]' \
#include <STDLIB.H></FONT></P>
. V6 d3 G0 T" }5 R- a( T  j<><FONT color=#0000ff>int compare(int *x, int *y)
* L) C3 Z9 D* b0 w2 F3 J' O: [# W{
" z- _8 q; M% X+ wreturn( *x - *y );
1 t0 V( K. l, O2 Q3 ]9 q( B3 y- t} </FONT></P>' q6 K% K+ `: X& H
<><FONT color=#0000ff>int main(void)
  z7 m' L) N2 d/ Z3 c# Q$ {* h8 p! |" |{
* Q4 v' z% }- Q' xint array[5] = {35, 87, 46, 99, 12};
/ b! i6 I, S) C. f& v6 M9 Isize_t nelem = 5;
( m! H( x6 I" a; x  z" a2 kint key;
: j2 g+ C1 P* w2 pint *result; </FONT></P>
3 i0 W" E  w; x, k- d<><FONT color=#0000ff>key = 99; / }. a# A3 `( O4 ]
result = lfind(&amp;key, array, &amp;nelem, ; g6 J; n) E1 \) p1 ~# a0 b
sizeof(int), (int(*)(const void *,const void *))compare); / Y1 P8 H5 L, e% L# r4 f* _
if (result)
" F1 Q$ o7 Q: b% Z/ Nprintf("Number %d found\n",key);
9 Z( \  m5 j4 Xelse # g  V+ ~8 W" g$ |( W/ n
printf("Number %d not found\n",key); </FONT></P>
% d' k+ ~3 c7 g<><FONT color=#0000ff>return 0; 4 I. Y7 U: R( ^( a: i
} </FONT>/ e  y  q: N3 @& M9 }

: `7 c; I9 m0 R1 M</P>
! z" v9 F0 }) {. H# s9 D6 u; a<><FONT color=#ff0000>函数名: line </FONT>
. y1 K. Z# K; G& u; b- Q功 能: 在指定两点间画一直线
/ Q# `$ P# [8 N4 |( R用 法: void far line(int x0, int y0, int x1, int y1); : D  A4 Y( `" B. g  s/ E6 c$ K- ?; a
程序例: </P>5 W1 b  h! }0 F: G0 W: Q* L, w. L5 ^
<><FONT color=#0000ff>#include <GRAPHICS.H>
- J3 W' d, r$ L, U#include <STDLIB.H>
3 v# v7 l. O$ C; A$ O5 A4 g#include <STDIO.H>+ n0 z, I' q2 T' Z7 R& c
#include <CONIO.H></FONT></P>
4 E" C6 Y& y8 d3 _9 W<><FONT color=#0000ff>int main(void)   r) o! w" m+ O
{
1 s5 H$ O  U+ s& X; Q/* request auto detection */
4 x% R9 w; N# @2 F9 |. Tint gdriver = DETECT, gmode, errorcode;
8 Y3 w3 _' v5 e3 Hint xmax, ymax; </FONT></P>2 T& ]) o, F. l0 I6 t
<><FONT color=#0000ff>/* initialize graphics and local variables */
7 g, ^" T. T# @* pinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>: c! _: A, Q1 w  Z4 G- _) {2 S& d
<><FONT color=#0000ff>/* read result of initialization */ ) T0 v) V) f3 f, ^7 p' g% e/ v
errorcode = graphresult();
' d. L$ u! B; v( J' R/* an error occurred */ 5 F8 n4 e+ z1 y) z
if (errorcode != grOk) * L: C: |! x' \# D: P5 D- Q( j
{ : W3 K1 W. x: @" G, w0 {% V
printf("Graphics error: %s\n", ; u7 r2 j9 \, d( P
grapherrormsg(errorcode)); ; g1 B5 y* ~, R* m/ d6 S2 Q
printf("ress any key to halt:"); " ]( k  y: z, R" U$ G  y" ~
getch(); 1 N0 o1 Z: ], ^
exit(1); 9 R0 z' F! \' I, f
} </FONT></P>7 Y( K* Q/ ~& c( w# L
<><FONT color=#0000ff>setcolor(getmaxcolor()); % U! I% A* |' |8 U/ {
xmax = getmaxx();
; ~8 f. O4 p0 ^: A# o& ]' Y" Q8 k* `8 yymax = getmaxy(); </FONT></P>
6 \8 ~9 w3 B. Z- ~* f& c) @4 N- b% W<><FONT color=#0000ff>/* draw a diagonal line */
, c9 Q" x. \" Lline(0, 0, xmax, ymax); </FONT></P>
- x* B( I' E5 {! a<><FONT color=#0000ff>/* clean up */ 1 ?  Y; b0 ?: ]" b/ G' \
getch();
8 U4 m& ?) y2 P" Q+ B% \* Gclosegraph();
) T! K3 I8 l# D$ n9 J4 `return 0; 9 ~1 M& Z+ L) y5 i& Y# |' r: o
} ; p' ~: q& ~" g3 [8 x
</FONT>- j3 u) J6 ~$ Z9 a, _
</P>
$ @- x0 G* D2 m6 T& |; [% C  L0 E4 |<P><FONT color=#ff0000>函数名: linerel </FONT>7 ^2 o* |  P+ t
功 能: 从当前位置点(CP)到与CP有一给定相对距离的点画一直线 $ L- Q* f  U4 h
用 法: void far linerel(int dx, int dy); . Q: l, i7 Y+ r+ X4 |, }; S+ |
程序例: </P>
4 ^% h( r. b5 \5 @0 \+ x6 @0 p<P><FONT color=#0000ff>#include <GRAPHICS.H>
* L* X9 b% Q- V$ z/ a#include <STDLIB.H>3 \$ r8 H# {7 s
#include <STDIO.H>
7 m) z4 v. B5 Z9 @1 Q#include <CONIO.H></FONT></P>5 y4 k6 d  N  G0 Z% K* h
<P><FONT color=#0000ff>int main(void)
3 t- G+ ^! i. F7 N; c{
$ _6 T9 j, N8 q9 W9 }7 ?  _" v/* request auto detection */ 2 W$ e1 W4 L6 ]" X5 R
int gdriver = DETECT, gmode, errorcode; * @/ d$ Y, T' J) F
char msg[80]; </FONT></P>5 ^' Z* w! @6 m; B0 q' _% D
<P><FONT color=#0000ff>/* initialize graphics and local variables */ % R4 C. g& Z  r) Z- z% p( W; s( Z
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
0 T) q* `% o5 Y6 j, A1 z: v1 B<P><FONT color=#0000ff>/* read result of initialization */ # |. Z/ H/ K; B( j& }
errorcode = graphresult(); 2 U5 [  v1 }& ?- U/ i4 s' T; K
if (errorcode != grOk)
* [9 i! ~4 i; i& N9 X- o% i! \{   g, V& ~" T( _+ C4 a2 E
printf("Graphics error: %s\n",   q. q3 u; T: b# R" w: n/ p
grapherrormsg(errorcode)); 5 w  A9 |: p: w* @- S8 L( M
printf("Press any key to halt:"); - W2 c. u1 b6 ]! K- x, T
getch();
; f2 s) o! T1 j4 x" c: Q, wexit(1);
8 E4 |" K) w( v9 q5 T  o* g} </FONT></P>- Q+ U& z; r) P2 x/ U
<P><FONT color=#0000ff>/* move the C.P. to location (20, 30) */
, D3 o* K- E" f1 {moveto(20, 30); </FONT></P>, Z4 V. j$ }4 V* ^; o! S- U* v
<P><FONT color=#0000ff>/* create and output a
9 v& U3 z! y( J% E4 \) xmessage at (20, 30) */ $ }% ^, d/ O) R& U+ c/ [
sprintf(msg, " (%d, %d)", getx(), gety()); " \2 S1 i" r6 n0 n5 }
outtextxy(20, 30, msg); </FONT></P>
' I$ r! b$ |4 a<P><FONT color=#0000ff>/* draw a line to a point a relative
: _  o) t( w4 }( T  w3 Y# l/ edistance away from the current & F  z0 H! W* ^
value of C.P. */
. s, k6 R6 d* k0 u" f! ~linerel(100, 100); </FONT></P>
) C2 v+ W( ?2 o5 {6 H5 s) e: K<P><FONT color=#0000ff>/* create and output a message at C.P. */   _" G! [+ @/ k
sprintf(msg, " (%d, %d)", getx(), gety());
6 G5 N) L* x; I: P  U4 F3 @7 `outtext(msg); </FONT></P>
( j7 T$ c! T1 V2 p) a<P><FONT color=#0000ff>/* clean up */
/ l! y$ t2 p9 _& cgetch(); + A$ e8 U! m: F9 ?8 U
closegraph();
, S- t$ H8 f: Ureturn 0;
' G/ [) o# n/ A+ H* T} </FONT>7 ~$ v! L: p  [; L
</P>
* b- A. @7 P- q) h3 ~5 C' c<P><FONT color=#ff0000>函数名: localtime</FONT>
* d; d4 s- P& Q. l& X* V, h) N功 能: 把日期和时间转变为结构
& i( X8 }4 n" |* B: r1 [用 法: struct tm *localtime(long *clock);
9 \) n9 j. }- b4 U程序例: </P>8 a8 Q- K  r0 j$ b
<P><FONT color=#0000ff>#include <TIME.H>
# |+ B4 a* w; f9 r#include <STDIO.H>8 e- P% i# o3 E1 D# g1 W
#include <DOS.H></FONT></P>
, s% g9 |, |- u6 I<P><FONT color=#0000ff>int main(void) 8 Z- s8 T# _3 z+ A) d% [! i
{
& B8 o7 {5 a- R' \$ @time_t timer; 6 u2 \2 b' ~) l
struct tm *tblock; </FONT></P>
8 k3 d  C  W# l4 c<P><FONT color=#0000ff>/* gets time of day */
8 Z9 }3 T" v$ ^/ W/ G) Dtimer = time(NULL); </FONT></P>. Z2 G. }1 R1 j# `7 P& p2 e/ }
<P><FONT color=#0000ff>/* converts date/time to a structure */
" P  C2 @+ `, y: t. \& \  ]  Stblock = localtime(&amp;timer); </FONT></P>7 X6 |1 N) I% q+ F  z
<P><FONT color=#0000ff>printf("Local time is: %s", asctime(tblock)); </FONT></P>8 ?3 D* K* b6 Q  a. w
<P><FONT color=#0000ff>return 0;
4 y+ r1 m. L2 S' S0 {# P8 s3 h) O} ! {7 I3 _( _  v: a. b* \6 u. |

- V* j) d5 @# ]8 d  ]* S" o7 x& C8 |' P. G% Y
</FONT></P>7 m2 F+ A) S4 R2 x
<P><FONT color=#ff0000>函数名: lock </FONT>
$ {/ ~- k! n0 p9 R功 能: 设置文件共享锁 ( o' M9 ^, z% z* j
用 法: int lock(int handle, long offset, long length); 4 d- T* _& p+ a3 j
程序例: </P>
9 o) D) m+ m6 g3 f<P><FONT color=#0000ff>#include <IO.H># H' g; ~, R0 a. K
#include <FCNTL.H>; z7 N! [& l3 ?' i
#include <SYS\STAT.H>4 Q4 S, V' D. M5 [6 x7 H
#include <PROCESS.H>
6 ]6 l; e/ T7 ]3 \#include <SHARE.H>, _( T& l9 u3 f$ r/ X: [1 m' C
#include <STDIO.H></FONT></P>
8 V% ~1 |3 D& b* |) F, z  D6 V$ Q$ _<P><FONT color=#0000ff>int main(void) $ q; v" w: ^% f% ]; G
{
4 h# w" S: c! i; E  U: @int handle, status; 8 H9 g+ X% D. |4 {, O' m9 d- p8 l
long length; </FONT></P>7 K4 s4 R4 t! C" H; v9 k1 u
<P><FONT color=#0000ff>/* Must have DOS Share.exe loaded for */
/ ?5 v- G/ `' k* h2 ?9 \9 C/* file locking to function properly */ </FONT></P>
, K' O; h4 @; d& d! H# B<P><FONT color=#0000ff>handle = sopen("c:\\autoexec.bat", ) m2 M- T9 R5 l7 `
O_RDONLY,SH_DENYNO,S_IREAD); </FONT></P>
4 F$ v6 F& E. b7 f- l& \' U<P><FONT color=#0000ff>if (handle &lt; 0) 5 Q/ x, l  I; M4 x
{
2 U. P1 ~. C7 i# }0 Aprintf("sopen failed\n"); / m2 u5 j# P6 u$ U* Y
exit(1); $ f! M2 `- G3 r- _
} </FONT></P>
! B/ S0 f$ k( [* O8 F<P><FONT color=#0000ff>length = filelength(handle); ; U& v. q2 E7 c$ e
status = lock(handle,0L,length/2); </FONT></P>  T5 }+ H: O* l% {% c1 W, A
<P><FONT color=#0000ff>if (status == 0)
( ^. G( L" Q+ F" d6 o; dprintf("lock succeeded\n"); ' d# f+ q- }! z( W$ t
else 3 k0 N' ]7 b1 C1 J& |( w  s
printf("lock failed\n"); </FONT></P>
" U% I( G# ]+ K2 G& {4 `- x- L<P><FONT color=#0000ff>status = unlock(handle,0L,length/2); </FONT></P>: n" N  f% n5 K
<P><FONT color=#0000ff>if (status == 0)
! s( K0 N6 `2 l, d& b( Lprintf("unlock succeeded\n"); ; A1 G* f% X; M) y' f0 A5 ^
else
( `% A" t3 _/ pprintf("unlock failed\n"); </FONT></P>
& }' c% @' C" P<P><FONT color=#0000ff>close(handle); ; e# s6 b7 w( K2 h6 C/ i# E
return 0;
0 x. ?, B# p- U: d& Z} ! C2 b9 o% O- E% |- y6 K
</FONT>2 O1 q, _( K* F0 V  j( c* X
</P>6 E: Y8 ^' z, |7 o4 W6 K1 ]
<P><FONT color=#ff0000>函数名: log </FONT>
4 S( @6 X) V9 l/ _8 J功 能: 对数函数ln(x) 1 r7 W5 x+ {# f4 O  J, V3 v
用 法: double log(double x); 4 H% j" T4 o7 ~1 R4 t" c* n
程序例: </P>0 y/ A4 }: B; ?$ M+ L
<P><FONT color=#0000ff>#include <MATH.H>
  Y4 @1 j/ b) S#include <STDIO.H></FONT></P>
( b: d0 [' i! \$ {' J/ [1 P<P><FONT color=#0000ff>int main(void)
. ~7 ?2 G& ?1 w, h0 W{
" g8 |+ ~) n* k; p/ Xdouble result; & w' K3 z7 L9 F) N: t3 M
double x = 8.6872; </FONT></P>% J+ o& c: F5 \7 F2 R4 j
<P><FONT color=#0000ff>result = log(x); * |0 G. G- z2 b8 Q
printf("The natural log of %lf is %lf\n", x, result); </FONT></P>  @6 `( \$ s- }/ h
<P><FONT color=#0000ff>return 0;
% Q% A% F" }7 s} ' n2 `3 T; z% P; V& A7 V; }$ k

" p/ h3 ?* V- }, W' c</FONT></P>
% G& N8 b0 K3 {1 P1 M0 y/ P<P><FONT color=#ff0000>函数名: log10 </FONT>
; G. N  m) q! ~  {功 能: 对数函数log
: m/ T$ }; Q- J# w( J7 z用 法: double log10(double x);
3 q* W2 W& c: @9 z, ?3 [程序例: </P>7 ]7 _( C/ ]# I8 Y( p" `0 P0 \
<P><FONT color=#0000ff>#include <MATH.H>
4 `# M2 q4 x2 Z9 u! q( _! D- `#include <STDIO.H></FONT></P>! D! ?% C5 X% D1 f: H% ~
<P><FONT color=#0000ff>int main(void)
. l0 `  e9 s3 k. ~{
0 U) M7 `5 S3 w& ]: D( idouble result;
* e( B+ p( M8 m2 N7 ^9 a' [1 Pdouble x = 800.6872; </FONT></P>
: a. s9 |8 u. t, s7 o- A+ ]' w# n<P><FONT color=#0000ff>result = log10(x);
3 U# o9 I' D0 Z/ t, fprintf("The common log of %lf is %lf\n", x, result); </FONT></P>
: |" ^8 A- Y# x' V<P><FONT color=#0000ff>return 0;
" P! L: X) k# l$ T$ z7 M- Z}
2 X9 _# Y, d- }1 C- z9 g7 j+ |
</FONT>
) M, V3 r3 s/ q! u% M</P>3 R6 M4 p& p6 q8 l% C
<P><FONT color=#ff0000>函数名: longjump </FONT>
! v! t. L  D: }4 n7 ]& q: e功 能: 执行非局部转移 5 n8 |3 v5 I: h  c& B
用 法: void longjump(jmp_buf env, int val); 2 M7 S0 i! \5 B# Q2 K* ]: [* }4 w6 u3 G3 i/ b
程序例: </P>5 F) [( m: a. b6 F% E- m$ @
<P><FONT color=#0000ff>#include <STDIO.H>/ s2 }1 w& E: w  _
#include <SETJMP.H>
! ]; ]# X  N6 V# K#include <STDLIB.H></FONT></P>5 y. X) s7 e. w5 X# N( X
<P><FONT color=#0000ff>void subroutine(jmp_buf); </FONT></P>! j: l( B- a, n8 r) c1 K
<P><FONT color=#0000ff>int main(void) % p5 @4 |! {( m4 }% b
{ </FONT></P>
2 k$ y% |' |, [8 Z<P><FONT color=#0000ff>int value;
9 `6 J: t4 y; v2 x% P; R. Zjmp_buf jumper; </FONT></P>
+ P$ |0 ]/ r2 B1 |9 b/ P3 S- z<P><FONT color=#0000ff>value = setjmp(jumper);
! f% P- ^! Z! ]8 D0 nif (value != 0) & i9 p( P4 \- ^! P6 G8 L
{
. h! o* m1 X% F; i% Eprintf("Longjmp with value %d\n", value);
6 m2 K# Q' N8 E- N6 d( s/ r1 bexit(value);
0 W; M1 O+ k' ]}
- y. e; o' G0 _1 w! Jprintf("About to call subroutine ... \n"); 7 q; r# Z! z) |; J: ~
subroutine(jumper); </FONT></P>
7 a. L' z! I% c. v5 z  H8 v( [4 a! ^( D<P><FONT color=#0000ff>return 0; - R/ `' J. v( W( F) [, f7 H8 F  L5 U
} </FONT></P>/ ~& `! X3 x  @1 a+ W9 R' Q. x) \
<P><FONT color=#0000ff>void subroutine(jmp_buf jumper) # c% `" Q9 F1 j% l; u
{
& ?! w. }0 v% |# Olongjmp(jumper,1);
+ R: v( h& Q+ ~. M/ c! w} 9 q- W5 R; e# h

2 T5 \1 t# o# {7 P6 Y; g$ F% a; R</FONT>
$ r8 \% z! d" G4 |) P0 w: v</P>7 q/ T  B& C/ h7 R7 s& W" e; b
<P><FONT color=#ff0000>函数名: lowvideo</FONT> + @" P; O; L0 j/ G' K
功 能: 选择低亮度字符
' g8 a; _+ f& r* t7 Q  ?1 x4 W+ @) U用 法: void lowvideo(void);
+ ~# Y+ n) \% p1 J  ?/ D% e9 O程序例: </P>0 ?  B0 ~# }$ H2 g3 _
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>2 \( I- b4 M8 E
<P><FONT color=#0000ff>int main(void)
9 K3 D& C0 K0 T2 c, o{
6 G5 U6 p+ P7 C) h, gclrscr(); </FONT></P>
2 ~! u3 O) D! I( F5 p1 f0 j<P><FONT color=#0000ff>highvideo();
2 k5 m( `  W; d* ]/ z# Rcprintf("High Intesity Text\r\n"); . `9 a1 [  @8 z( R
lowvideo();
1 f5 {1 H! V  y  Kgotoxy(1,2);
# z7 p: j; k+ Ucprintf("Low Intensity Text\r\n"); </FONT></P>
  Z# ]3 `! {3 ]' S: O* E9 {$ ?3 |<P><FONT color=#0000ff>return 0; / U% ]' c8 \' c3 Y
} . T9 I4 }9 J$ [& U+ S) t

8 y8 t0 r& X4 O4 X* X</FONT>/ l9 w( q$ p/ ?3 {+ V9 K- A
</P>
. Y* o! |- k% G7 P8 t- h2 ]% ^<P><FONT color=#ff0000>函数名: lrotl, _lrotl </FONT>9 l, w' `' N3 q" t
功 能: 将无符号长整型数向左循环移位
# Y3 K- f; B" a2 l用 法: unsigned long lrotl(unsigned long lvalue, int count);
: ]  g6 x9 ]2 B3 V( A" C& _$ @unsigned long _lrotl(unsigned long lvalue, int count);
% t/ N9 w- U! Z; v; D4 b程序例: </P>
) W; y# w) Z8 ^  M) V  o7 F<P><FONT color=#0000ff>/* lrotl example */
2 n% h7 c5 @# o2 h; @/ _#include <STDLIB.H>
" U5 F4 f5 `) J* g3 z( f! Y#include <STDIO.H></FONT></P>
1 h! r3 K! ~/ w, J$ X" X3 ?<P><FONT color=#0000ff>int main(void)
; k& K9 _2 ]7 \" K{
6 x; z2 N! U# L7 aunsigned long result;
" B7 B: n% v: e& gunsigned long value = 100; </FONT></P>
  H7 G$ F% \( j+ V% A% @<P><FONT color=#0000ff>result = _lrotl(value,1);
7 {' F) x2 u" p, K$ N( w5 vprintf("The value %lu rotated left one bit is: %lu\n", value, result); </FONT></P>
2 {3 d7 B& n4 s. G- |<P><FONT color=#0000ff>return 0;
# o1 K( c3 f  R6 ?( L} + Q# h5 m7 T2 R) }4 T
</FONT>1 ^) F. w$ r4 L" b0 a8 O. y6 W
</P>
6 w6 @- f9 }8 g/ J$ E<P><FONT color=#ff0000>函数名: lsearch </FONT>$ y/ a( [% S9 w/ l" g' S* p6 {) e& L
功 能: 线性搜索
* I: G* r: r& f) y: u用 法: void *lsearch(const void *key, void *base, size_t *nelem,   s. K; m! {/ Q/ Q0 l
size_t width, int (*fcmp)(const void *, const void *)); 7 q2 \0 \: O7 H/ \# g/ X2 f
程序例: </P>& _( {6 z" u0 s
<P><FONT color=#0000ff>#include <STDIO.H>+ f0 D3 u& O7 i
#include <STDLIB.H></FONT></P>! F) m" i5 o+ X. w( D+ w2 V
<P><FONT color=#0000ff>int compare(int *x, int *y)
7 n( p0 h6 W- w{
2 U+ d. R/ v+ I5 K2 ^5 ?4 Rreturn( *x - *y );
& p3 R6 n6 |1 H& @} </FONT></P>; s% p0 j) l- J# m' G
<P><FONT color=#0000ff>int main(void) : d4 D4 i& \9 Z
{ # g0 @0 s+ D! l% }4 S
int array[5] = {35, 87, 46, 99, 12};
) _& y  {" H7 ?8 o4 t! Zsize_t nelem = 5; 5 g4 E1 n. {' a8 N; |
int key;
. C% `  [$ H3 m1 `int *result; </FONT></P>0 s7 [: y2 F4 r/ m
<P><FONT color=#0000ff>key = 99;
4 t# r1 i$ {+ E$ M0 G( I4 q% `result = lfind(&amp;key, array, &amp;nelem, ! L" q5 |( e  h6 k1 U
sizeof(int), (int(*)(const void *,const void *))compare);
/ t5 A! v5 ^& hif (result) + i( N) `* Y9 V" E) k
printf("Number %d found\n",key);
, y- ]* s2 Y) ?1 a6 _5 e6 helse
+ Q) `; [6 E. lprintf("Number %d not found\n",key); </FONT></P>1 }7 a$ u7 f4 r! W7 H2 v* c  o3 N2 E
<P><FONT color=#0000ff>return 0; 9 @( s. {2 e0 x& A
}
+ f# H) c7 K6 ^' D; {; Q& @$ ?7 u# U/ R! d7 Y2 _
</FONT>0 o4 U) e) R8 h9 e+ R, `7 P+ ^
</P>0 E- e/ _8 X: z4 e
<P><FONT color=#ff0000>函数名: lseek </FONT>  ]7 B, p- W8 a9 w
功 能: 移动文件读/写指针
, E; |3 g* q8 @% }2 G+ w用 法: long lseek(int handle, long offset, int fromwhere);
4 V+ {+ k: o3 N7 r程序例: </P>' ~2 k+ @8 G. n8 E" j0 M: s
<P><FONT color=#0000ff>#include <SYS\STAT.H>
- {# D- p+ v. {#include <STRING.H>; {5 R$ n& ?! l0 |- A# _0 G8 G) j
#include <STDIO.H>5 A0 l4 F- x$ H/ n0 x
#include <FCNTL.H>
; V7 o/ I5 Y$ t& G8 G#include <IO.H></FONT></P>9 G8 i0 ]; e( `# F0 A* d
<P><FONT color=#0000ff>int main(void)
) L9 w1 @9 K* ?2 {{ & I1 k; A" o& g& E& C" H5 V
int handle;
& t" i+ @* o' l8 w  s* L" H) Dchar msg[] = "This is a test"; , c/ a* W& C4 G' i
char ch; </FONT></P>
# A% u) Y: ?6 ^# {4 Q! s  [: n<P><FONT color=#0000ff>/* create a file */ 3 F- e/ a6 p7 y$ s; X3 b! ^
handle = open("TEST.$$$", O_CREAT | O_RDWR, S_IREAD | S_IWRITE); </FONT></P>2 W5 D2 |9 |3 F1 f4 O4 {+ f
<P><FONT color=#0000ff>/* write some data to the file */ 0 p) U0 a+ n$ u! d  ^7 j- m
write(handle, msg, strlen(msg)); </FONT></P>
+ p  q: D( m6 d$ c<P><FONT color=#0000ff>/* seek to the begining of the file */ : _6 K; Q% ^$ d
lseek(handle, 0L, SEEK_SET); </FONT></P>8 X7 c; E! ]( c' b: D4 w
<P><FONT color=#0000ff>/* reads chars from the file until we hit EOF */ , a+ R, f3 s7 H' e5 ~1 `3 O' @) ?
do * N* b6 b& b* `) l" w' {# g* k
{ " L' C. o+ J! g! e/ Q- _
read(handle, &amp;ch, 1); 3 Z/ E/ `4 U- P( z5 _: c
printf("%c", ch);
! l/ d& o# ]3 b' r% ?} while (!eof(handle)); </FONT></P>
6 V5 b: A! \4 C3 P0 a9 j<P><FONT color=#0000ff>close(handle); 1 W/ e% d8 g0 \1 G4 t/ k
return 0;
0 ?, j5 F3 z0 c$ {2 ]}
6 r0 a9 y3 }/ E$ q+ S+ q</FONT></P>. {3 T$ G* J& h
<P align=left><FONT color=#0000ff></FONT> </P>




欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) Powered by Discuz! X2.5