【程序87】
3 }% e. X% Z" F: Y題目:回答結(jié)果(結(jié)構(gòu)體變量傳遞)
0 V+ X% ~7 P- j4 L' b6 h2 I: \1.程序分析:
3 P. d2 s' O2 m. O2.程序源代碼:
9 d6 H9 }0 B7 q, t#include "stdio.h"
; z0 p% @6 \7 Q% @2 h estruct student
0 s, [8 K+ `' w* \. ^* S( E2 U{ int x;
# v* f5 O1 s2 F) vchar c;
. F& F: Y1 n+ t Y} a; : G, \4 t0 [1 H8 R, z3 s. M! \
main() 8 j& H- G# b2 }, Z. E3 x
{a.x=3; . r6 L( h* W; @; O: D6 h* `' g
a.c='a';
2 x/ x, v5 x9 r2 F* J0 L: h; Vf(a); . [, S( Y3 Z( [9 P& C
printf("%d,%c",a.x,a.c);
1 U$ b- K1 l9 j9 a1 f} 1 j g: A5 s* ?: I) _
f(struct student b) 4 e8 m* e4 n$ [3 R- g) [+ F$ Z9 D
{
, t* ]1 c8 g) P1 F9 E% [( ib.x=20; ' y" m* J" C% d4 K1 L
b.c='y';
* T. q$ S" ^) K# t0 g}
' d" Q4 s. e: H% j5 z; h==============================================================
3 e- e u" d; C4 O* K `+ i2 L【程序88嵌入式信盈達(dá)企鵝要妖氣嗚嗚吧久零紀(jì)要】 ' {9 e X+ P& ?3 S
題目:讀取7個(gè)數(shù)(1—50)的整數(shù)值,,每讀取一個(gè)值,,程序打印出該值個(gè)數(shù)的*,。 / a- _+ N y6 V. [2 I* j
1.程序分析: # z0 N) x: ?# x- l& ?: H* e$ j
2.程序源代碼:
( p) w) k: ]0 G4 L" M8 K Q7 x' Hmain()
9 i8 s# H8 d- r( K{int i,a,n=1;
$ \9 F4 G' _* s _5 y4 _3 _: swhile(n<=7)
* b2 X6 }$ k3 M{ do {
* [# d, e( {4 R5 ?$ Q4 uscanf("%d",&a); 1 v. s, l9 | D/ d2 @. O! o, v
}while(a<1||a>50); 4 h0 D. n' |; _5 o, A4 b
for(i=1;i<=a;i++)
6 m* u7 q* {$ k7 j1 s$ Sprintf("*");
# v1 w9 y G1 {+ c6 b: F. X( p1 mprintf("\n"); ! f" {0 P& @5 `/ Z h$ X$ j
n++;} % C5 a2 g' q8 t6 U# ?. E
getch(); / B8 T5 d/ N( p: C! c
}
6 [2 V3 {2 ]0 V0 f4 _6 J============================================================== + @, S- S4 [( l) n. u+ R
【程序89】 $ O! r8 _. |2 b! x0 [! u. a$ s" N
題目:某個(gè)公司采用公用電話傳遞數(shù)據(jù),數(shù)據(jù)是四位的整數(shù),,在傳遞過(guò)程中是加密的,,加密規(guī)則如下: * m; N% g1 e3 I |7 a' R
每位數(shù)字都加上5,然后用和除以10的余數(shù)代替該數(shù)字,再將第一位和第四位交換,,第二位和第三位交換,。
1 Q* n M9 C) W1.程序分析:
8 @ i% P' M& N6 w; s) b: M6 t2.程序源代碼: 1 Y6 X* o* g& h8 {" d
main()
8 g% q& E5 l3 P( e{int a,i,aa[4],t;
5 K$ T) W) U1 u" Y9 L2 ~scanf("%d",&a);
" v4 X# ?7 ?* Caa[0]=a ;
3 s* k, L0 U+ I Z- U1 u3 eaa[1]=a 0/10;
1 H9 m2 \* p2 y& g* O6 T+ Qaa[2]=a 00/100; ' |6 @0 C8 a5 Z
aa[3]=a/1000; 1 a- ?( \- ~2 K) d' S
for(i=0;i<=3;i++) 6 J( L% v( g$ S: p$ W3 x, ^% Q
{aa+=5;
/ @* u& z/ N4 D8 G3 |, `aa%=10;
D/ s6 v9 R8 d7 M( j$ M}
6 c, x0 p G& n9 i9 x2 ~for(i=0;i<=3/2;i++)
3 q9 a. w# V' B6 R5 _{t=aa; 2 K1 y3 M0 K+ l" ~8 h
aa=aa[3-i]; * R. n% r- h9 V2 }" W" l$ T
aa[3-i]=t; , h' T9 z9 z r7 ?" h$ ]
} 6 g8 c9 j! u. t3 D
for(i=3;i>=0;i--)
' C8 t, ]3 W- M' `9 rprintf("%d",aa); % i8 g& d3 w! h; i
} + c& o( i! A# l/ u+ C
==============================================================
/ ^" \, Y! R& D0 d+ L( w【程序90】
! b+ a3 a0 ^5 w! }, H: }題目:專升本一題,讀結(jié)果,。 , t6 @: A8 G$ V' U9 K
1.程序分析: + ^3 O( E! \# r$ Z6 } s9 B
2.程序源代碼: / c# m, [" G9 J" Z
#include "stdio.h" & S7 a8 R L+ o5 C/ d+ O
#define M 5 7 K+ T$ I) I$ l
main() , j- s! D0 }; x X: B
{int a[M]={1,2,3,4,5};
/ M3 v' F# _7 T/ p8 @' A. h5 Cint i,j,t;
( b4 t% }, L6 I/ }+ }, ?; f- pi=0;j=M-1;
( }, ]6 L0 i2 W5 f2 R2 m2 Owhile(i {t=*(a+i);
/ R' W. h8 q2 Z*(a+i)=*(a+j); + ?# U {! ^8 _5 i, r/ d
*(a+j)=t;
+ t6 ?1 |$ ^- Yi++;j--;
/ E. E+ V/ H& l+ R' c7 _}
0 I: s5 b% V$ r4 qfor(i=0;i printf("%d",*(a+i)); & g4 J% X7 l/ v9 z5 z' @+ b
} 5 f( V. T/ v. a- ]: P4 [
【程序91】 7 y, F- {" P s
題目:時(shí)間函數(shù)舉例1 + Q) F5 [, Z3 J% q' x# [9 E
1.程序分析: 0 W h( B8 I- s
2.程序源代碼: ' S: E9 K+ P4 O6 P/ J! X1 P
#include "stdio.h"
* |0 U6 Z' p8 y; Y$ t#include "time.h" / }! D B( @8 p
void main()
' ?/ _( C$ C! I7 ?- S& A{ time_t lt; /*define a longint time varible*/ 9 T! }. }. _' J5 d% P
lt=time(NULL);/*system time and date*/
2 {/ Z w" [& P* S& l+ Qprintf(ctime(<)); /*english format output*/ + E; t8 ]) h7 L
printf(asctime(localtime(<)));/*tranfer to tm*/
3 X7 h) G; b2 ^1 S( x8 ^printf(asctime(gmtime(<))); /*tranfer to Greenwich time*/ 1 r. ~! s1 l& }5 t+ F5 e
} & W# A' C8 X+ x* | q4 R8 O5 Q
============================================================== ! c6 j% {; N2 b7 h; Y& [- F: c0 E& z
【程序92】
" }" Q$ O: ?3 q3 v- H C3 Y題目:時(shí)間函數(shù)舉例2 ]1 [! t4 s+ {, @ g Z
1.程序分析:
; f5 _" {- x9 P/ }% V( D8 P3 w. ~2.程序源代碼: % e1 S# I% b* @2 J8 X
/*calculate time*/ ' Q, W* H, J& ]2 o! `- c
#include "time.h" P0 o3 u+ W5 v! x5 R3 V
#include "stdio.h"
8 z- S# a6 R$ a7 `5 Omain() 1 E* H2 n2 G/ O2 {: I" B7 W
{ time_t start,end; 4 S& m$ d( J' A, F/ X3 C- Q
int i; 3 ]# T' k# ]3 ^2 B3 A5 W! W
start=time(NULL); 6 s# b {$ e$ m% `/ Q" ~
for(i=0;i<3000;i++)
1 J- c' S( q3 }* ~5 g{ printf("\1\1\1\1\1\1\1\1\1\1\n");} % Q* ^) h+ d7 `$ j6 E+ J2 @
end=time(NULL);
( u0 B2 {3 G5 S# F! {, ~) cprintf("\1: The different is %6.3f\n",difftime(end,start));
; n. u' c9 M" X3 W" h* N% A}
* m( _$ W$ N% }: b- v+ x& ] t: a: ~============================================================== - R& _& Q& k. P6 p7 p
【程序93】 m$ K, y1 Z8 t
題目:時(shí)間函數(shù)舉例3
8 {0 H+ U( V0 f: N1.程序分析:
" d% ~: i3 M) g2 m+ h4 b2.程序源代碼:
& i& S; I) }3 v ^7 y/*calculate time*/
J7 W6 S' N3 a#include "time.h"
: N0 g7 K& t9 v7 Z- L4 c#include "stdio.h" 3 T# R. v' Q3 i$ ^# } M; i$ w: G8 \
main() : o8 g) Y, `1 D- c% E" E4 A, {$ u
{ clock_t start,end; ! u8 r [7 _' C. ?
int i; + i0 D i0 S: s( t
double var; - `/ o& ^6 O1 k! u5 r$ \
start=clock(); / i2 Z$ Y0 P! @
for(i=0;i<10000;i++) ! r0 ^' K/ M2 b6 `( Z
{ printf("\1\1\1\1\1\1\1\1\1\1\n");} * {/ |( m$ {3 i4 }
end=clock(); , u" H) O F: c/ [, F, \
printf("\1: The different is %6.3f\n",(double)(end-start));
$ ^" c% R2 l5 h/ b i}
. b% X7 D$ y; q0 S& `============================================================== 5 W) q8 J; c8 D, o& m1 W/ _
【程序94】 6 S* n& K" q/ s" B1 J
題目:時(shí)間函數(shù)舉例4,一個(gè)猜數(shù)游戲,,判斷一個(gè)人反應(yīng)快慢。(版主初學(xué)時(shí)編的) 0 \# N0 _8 S# K1 u1 Z/ M( B" C
1.程序分析: / |% ~( @8 b7 [1 O$ V) j0 h+ v
2.程序源代碼:
7 ?# t# X E, k3 m! `( S#include "time.h"
; Q6 X8 E* z& N#include "stdlib.h" 6 u$ Y) R) G# P
#include "stdio.h" $ E5 D$ H, }/ u/ g0 d
main()
3 a: m' q0 b g% l+ n+ p# f" U{char c;
& K" r8 ?8 ~$ ?* T3 O' Yclock_t start,end; 8 F( h. @9 D8 _0 g- z
time_t a,b;
7 U5 t6 I4 M' C; Y8 z1 Fdouble var;
: `# X" C/ Z( q/ s: O7 ]int i,guess; 9 C& b* x3 T; K
srand(time(NULL));
* M6 @3 T5 t) u. Mprintf("do you want to play it.('y' or 'n') \n");
/ g$ f0 T7 G# P1 [loop:
0 Y& N6 j9 ]& f* {while((c=getchar())=='y')
; R6 Z4 I; ?1 u! j' e! R{
0 @: K- Y: M' U' u! `: Yi=rand() 0; ' f/ `+ c9 z! J5 @1 Z+ q
printf("\nplease input number you guess:\n"); + m. e! Q4 {1 ~7 `
start=clock(); $ c- T& P* T2 i/ S; \' w
a=time(NULL); 3 P B* v. o9 B( e$ K. }$ I; T0 Z( h
scanf("%d",&guess); ! D* z2 C7 A, }3 G! d4 p
while(guess!=i)
4 ?. [/ u4 q) Y{if(guess>i)
. c# _( G% h+ j2 P{printf("please input a little smaller.\n");
' l2 ]% R; O. T* U8 Mscanf("%d",&guess);} ; |7 R0 D9 k& z& Z
else
5 `- J! G! K' d6 m% F6 v{printf("please input a little bigger.\n"); 6 L, _: c; s. ]' ^' h& ?: X( C
scanf("%d",&guess);}
) x: J1 P( B$ w0 C} - E9 z8 F6 |! Y& S$ b) K+ D+ A O7 A* Y
end=clock();
% `3 C; P o) x- pb=time(NULL);
% q* r+ s/ u' } K( v$ Wprintf("\1: It took you %6.3f seconds\n",var=(double)(end-start)/18.2);
. M( `7 X, A+ o l% Uprintf("\1: it took you %6.3f seconds\n\n",difftime(b,a));
+ P0 L* s) ]7 [4 U8 O9 f9 H1 s/ j2 Mif(var<15)
( q/ v9 V& H) h' U7 } Oprintf("\1\1 You are very clever! \1\1\n\n"); * p2 h9 G5 c5 B: L+ D. p+ ~
else if(var<25) ) o& }$ E) {/ R% g
printf("\1\1 you are normal! \1\1\n\n");
. j4 B' _! w0 n, kelse # }- t" ?- [( ]) ]
printf("\1\1 you are stupid! \1\1\n\n"); - }& ^9 r O: N+ e
printf("\1\1 Congradulations \1\1\n\n");
2 u+ @. U2 @1 a, S0 ^: }' n( p4 A9 M- hprintf("The number you guess is %d",i); 3 ^$ I9 q4 \) ]' l* e- v+ @ c
} # {# I$ J3 a1 {: l
printf("\ndo you want to try it again?(\"yy\".or.\"n\")\n");
5 q1 ?; K1 w# E. {* @: a1 M2 kif((c=getch())=='y')
7 x; A7 {5 f; o m* N& Cgoto loop; 9 F, x; u. ?/ \ n' c4 w- E6 O
}
4 _/ L/ @' r' u4 W/ e |