【程序87】
( L$ K' H+ @) w w7 f7 Q题目:回答结果(结构体变量传递)
/ a; h r/ d: E8 W1 A! R1.程序分析: # W; C( x7 ~& y4 v$ ] T
2.程序源代码: ! ?) B' B2 Q6 P% c! L& l6 p4 h ? H
#include "stdio.h"
* k) j ^2 T; z, sstruct student
0 u$ Q! y, I0 f! V9 r0 U! ^6 ^{ int x;
$ }* e+ ^+ z3 P) C6 C1 j2 j$ T; `8 ychar c; ) V) H/ c m d+ K% m0 a
} a;
2 T2 t9 c8 ]9 n- jmain()
9 E3 `4 `( x- }# m9 S{a.x=3;
# M& |1 B! s3 Aa.c='a'; 4 N, L; O* z* F; g4 F2 y5 M2 f
f(a);
+ K9 l, S( q P, k$ x7 L' lprintf("%d,%c",a.x,a.c); % ]; P, {% l8 r1 a6 `( T5 I
} ! B8 ^3 J! o5 [+ ~& V: N
f(struct student b) 5 M7 n! H/ A+ b0 X
{
9 Y/ f/ _7 z4 O. v9 Rb.x=20; 3 Y1 P, `) g# T$ n4 E
b.c='y'; ; b4 Y. A G4 l( b# O: ~9 l# i* m
} 5 t8 f* T# G2 y) ~
============================================================== ; W. a) k! @' G. h. |
【程序88嵌入式信盈达企鹅要妖气呜呜吧久零纪要】
8 O: P, K' S* ~% Z9 e3 v. f题目:读取7个数(1—50)的整数值,每读取一个值,程序打印出该值个数的*。 3 b' q4 C8 D; J) Q* X
1.程序分析: " x. O G2 D* N
2.程序源代码: ; u v* T5 {0 f- _
main() 8 R/ I& L" Q' e) m
{int i,a,n=1; ! |0 |6 a9 P u( U# U( l. j
while(n<=7) ( _7 D% E4 w3 I! C1 c) ~) E
{ do {
; z Z% Z& T4 T- o) Oscanf("%d",&a);
$ z+ ?# {/ H' l' E& e}while(a<1||a>50);
4 k6 Z' a1 Z. S7 j' bfor(i=1;i<=a;i++) m( N9 Z5 g r# |; \
printf("*");
! O) o, m4 W; R( o4 c3 ~. kprintf("\n");
: x" _! c* c0 i2 On++;} . u, L% v( D* \- m% K3 A9 y; A& z" A
getch();
8 L6 q& U5 C0 o" H2 y1 |7 a}
$ O" F- F" E4 e==============================================================
% W, d: E0 L8 n0 {6 a9 p5 Y【程序89】
7 V! b- B2 v0 J7 R% M( ?1 `0 S题目:某个公司采用公用电话传递数据,数据是四位的整数,在传递过程中是加密的,加密规则如下:
0 @' G+ q) S# G每位数字都加上5,然后用和除以10的余数代替该数字,再将第一位和第四位交换,第二位和第三位交换。
0 P# |! L9 o; X/ V1.程序分析:
+ k1 p8 }9 G5 }' H2.程序源代码:
+ D6 L( F% N/ P/ D5 W. U' u' @, pmain() : j( c% k( D# y) C$ i6 J2 ~; \% T8 X5 O
{int a,i,aa[4],t;
& M' V' y, d$ `* P$ U1 F0 w4 lscanf("%d",&a);
. p- K; ]$ l! Paa[0]=a ;
4 d( H9 k7 x; C6 d. w( Aaa[1]=a 0/10;
/ Y* h C0 b' @7 l- |- uaa[2]=a 00/100;
2 s( J! r Y7 p# ?! paa[3]=a/1000; * T9 x2 q4 Q p: A6 V% L) L" w' \
for(i=0;i<=3;i++) , Y( ]- [! v; Z3 h/ M
{aa+=5;
. x6 o: W( B- r& T3 @* \6 S8 H) \aa%=10; % V. p* `7 @% C( M
} 2 E' _! Z& i8 |% d V' P
for(i=0;i<=3/2;i++) 0 L: k. ^3 V# n0 r, w; C% F2 J
{t=aa; 1 J1 ?5 Y# i, ~& O+ I' r, F" A
aa=aa[3-i]; & D6 w8 [( ], P- h' J
aa[3-i]=t;
1 H3 ]' H5 b5 t, t} " p; X" p W. M9 E* ?
for(i=3;i>=0;i--) ; ~& q/ d$ \1 X8 @& p! m8 P5 J
printf("%d",aa); $ V E7 ?/ w" ]
}
. {" h, R# b$ y: T& N8 T============================================================== 0 D$ E/ L2 h- ~( B: N
【程序90】
: P7 [( w. Y; V* n# l题目:专升本一题,读结果。 # X/ |6 s" L, A) p
1.程序分析: 8 ~* T* ]% m# J$ i8 D) G
2.程序源代码:
1 G: `/ h4 p& T" Q#include "stdio.h" 3 l0 J6 A$ M. G; L; _( o3 X5 A
#define M 5 % \" @4 G7 C% C# I; Z; V) S
main()
# [1 N6 E) E( R( S. t6 r5 r{int a[M]={1,2,3,4,5};
! l% U+ Y; ?4 `) @5 e" [; M& Qint i,j,t; 0 q% r/ |/ N: \
i=0;j=M-1; 0 {# b4 T/ u5 L
while(i {t=*(a+i); 7 y! y1 Q9 Y0 k2 x& r& r9 p
*(a+i)=*(a+j);
/ [4 u2 @) M# K5 y# p% W2 P% i*(a+j)=t;
5 m1 X; p0 |" h" ` N6 i- G1 Mi++;j--;
: B" @7 n( D8 T. N$ J A- }8 H! z* u}
% a- _# F! D r( k% Bfor(i=0;i printf("%d",*(a+i));
% p' i4 d: p( W1 G}
7 Z! x& g& r! g( M+ V) [. q X& E' j【程序91】 $ q$ T3 A ~5 ^: T }( L
题目:时间函数举例1
3 H3 J* V4 p% D, r3 U5 P0 o" {1.程序分析: % c& b! @ R/ s5 \. O) a
2.程序源代码:
, e0 `+ N* C( U#include "stdio.h" ! K" P% n8 a0 h5 u0 @( B
#include "time.h" * P' }% r, I( a$ p5 U- x/ E p
void main() " @- w8 i, R3 t+ U+ r
{ time_t lt; /*define a longint time varible*/
2 M3 Z, l. d& q% Z6 Flt=time(NULL);/*system time and date*/
/ W& V: Q/ F. m) b0 [printf(ctime(<)); /*english format output*/ 5 w: R3 ?9 A2 a8 a# t3 ^4 a( r
printf(asctime(localtime(<)));/*tranfer to tm*/ ( R" T, `9 z' F; A
printf(asctime(gmtime(<))); /*tranfer to Greenwich time*/
! Y% B7 b* a' m/ |5 J9 i} 8 W; {% q6 I% n$ e: D1 d
==============================================================
3 r9 \7 O. |, b) |【程序92】 5 S' G' e- i) q% p- }: m4 A' c
题目:时间函数举例2 $ a, L8 U0 I; P( e/ F3 V! Z
1.程序分析:
|* J' o4 K7 o7 \8 d2.程序源代码: 2 j2 x. X$ ~7 L8 j! l: t
/*calculate time*/ & R2 U1 ?( U+ M. w
#include "time.h" ! a( C% b0 q/ F8 f T
#include "stdio.h" / ?! n4 _$ V! z- x5 o8 N* U
main() * w) e( k, G% C& Z
{ time_t start,end; * O) n$ m0 c( p5 S6 s4 q0 Z
int i;
" t: f: c1 \6 h1 u* ystart=time(NULL); 2 ` x2 d. ~, Y. w: F! F* N4 f( H
for(i=0;i<3000;i++) & J: Y1 t5 G- N2 l- ^* u$ U1 J# v
{ printf("\1\1\1\1\1\1\1\1\1\1\n");}
3 D0 ^, N( {% t# q& s8 ~; Y' Iend=time(NULL);
, |( H% e" P! V" Dprintf("\1: The different is %6.3f\n",difftime(end,start)); " N$ R* l: [/ e/ D2 y0 K
}
8 J, P% f4 V( o" [==============================================================
! v1 j' f" e4 d% G【程序93】
- T5 p5 L7 C# X7 w5 m/ s m) ~题目:时间函数举例3 O5 H7 o5 ?$ p1 Y3 I
1.程序分析: $ }+ @" ]2 @) d8 Y/ n: H
2.程序源代码:
) e% Z" T+ x) z [, z& |/*calculate time*/
( q* w! Y: t& ~$ Y3 b! @8 c y#include "time.h"
$ K. x/ g: P2 [$ E#include "stdio.h" % q, _/ s: k/ X9 Q& N) Q
main()
, B% Z+ \& ?' q7 P{ clock_t start,end; ; S: F3 `- z" b4 s
int i; ' Q5 ?" a3 X- F4 R, A! y3 a
double var; ( [. m2 \ y" _- Q
start=clock(); ' Q I \; }* A# e
for(i=0;i<10000;i++)
5 H* L5 F F* l/ X' e, X{ printf("\1\1\1\1\1\1\1\1\1\1\n");} % R6 F6 \* f1 c
end=clock(); 3 R# j8 M# Y1 L' F; W# J7 D
printf("\1: The different is %6.3f\n",(double)(end-start));
. X4 ~" G# j# u} 7 ^7 Y; R9 s! d/ `* [
==============================================================
- P0 b$ R4 h. S: j: I5 N【程序94】
/ u7 t& C2 |; \% Z J+ {3 Y1 ~题目:时间函数举例4,一个猜数游戏,判断一个人反应快慢。(版主初学时编的)
5 v6 H2 Z$ } O1 G" v) \ K1.程序分析: ' a9 W! ? l2 U1 I/ S
2.程序源代码:
8 D7 ^6 D# J/ R# j; L0 d#include "time.h"
6 m6 C( y& R$ X9 i6 [) c' I# q+ _#include "stdlib.h" ( r! o5 d% y7 m( Q, v& N" l
#include "stdio.h" " Y5 j* A2 V- g" X, W2 k
main() ! k4 m) g& Q6 p2 U; x
{char c; 7 e/ u! h( }- ^6 |) A1 S/ e
clock_t start,end; 6 F) q% d9 ^* g9 `; S: C
time_t a,b; - e' q) C6 s0 \, v
double var;
* f! b$ l+ r1 s- i3 Z* d( {) hint i,guess;
9 P! \% ?" n' X8 X/ ` D1 e9 Y2 Jsrand(time(NULL));
9 t( E7 F7 L. v/ h5 wprintf("do you want to play it.('y' or 'n') \n");
9 W" G1 L0 O0 Jloop: ( u0 J5 l! G6 M. t( N0 k; ^% S
while((c=getchar())=='y') 9 L/ _" P, E0 ^6 R p% u1 d
{ & R( w K" ` t* }+ F
i=rand() 0; 3 V" a" m/ q. y9 J% p! }- r7 p$ k% W' V
printf("\nplease input number you guess:\n");
/ u$ g" ]' U: Q) g% P8 gstart=clock();
: m' B0 d" v: B, Ga=time(NULL);
8 T( v' @& b1 w: r' z i( yscanf("%d",&guess); . O h4 U K x6 H7 |
while(guess!=i) ! r1 \- V M$ W
{if(guess>i) 1 A S% F$ U) \) Y( A- M
{printf("please input a little smaller.\n"); / Z: M9 W& Y. }4 ~6 B9 w& M
scanf("%d",&guess);}
2 A g, S) y6 Y1 X7 n+ Q( Y; x( yelse
9 A# t. ^2 L+ m. w" K# t+ W& g$ H{printf("please input a little bigger.\n"); 2 U; b' N, {" Q# K4 K
scanf("%d",&guess);}
4 x( M& |7 i% }1 E6 {1 w} . L) ~4 \9 P( M
end=clock();
# q/ X7 x2 _2 \ t" j5 c/ B/ Bb=time(NULL); 8 R( R2 M2 k/ N1 T! T, j5 [7 [
printf("\1: It took you %6.3f seconds\n",var=(double)(end-start)/18.2); ! P. i8 I+ ?# @8 N2 R
printf("\1: it took you %6.3f seconds\n\n",difftime(b,a)); . I8 v/ X$ H3 b0 W. P4 r
if(var<15) x$ q7 @# }' `9 d' j9 J2 W* O
printf("\1\1 You are very clever! \1\1\n\n"); $ b s0 ^; b9 W0 F5 f2 e, R
else if(var<25) . V0 a/ p$ V* \2 d
printf("\1\1 you are normal! \1\1\n\n"); ) ~! t; y, b/ s$ T, F. c' q& q$ A
else
/ W) J% K+ R! a8 zprintf("\1\1 you are stupid! \1\1\n\n");
: L" `7 S0 |, m4 {* p+ b! X% Sprintf("\1\1 Congradulations \1\1\n\n");
! V+ ~! f- Y! v! \4 yprintf("The number you guess is %d",i); 9 V' I3 q1 }( l, }9 H
}
& r* D0 P& P; [. u. `* [printf("\ndo you want to try it again?(\"yy\".or.\"n\")\n");
( U- E. I" {' P' q; \8 M4 sif((c=getch())=='y')
( K8 e0 M4 j# [7 T& s' n; Vgoto loop; 5 c1 {: |9 H3 i' P; B" T& y
} ) L- H2 A, ?6 x1 l
|