A. c語言考試 編寫程序計算98765+9876+987+98+9,輸出並計算結果。
#include<stdio.h>
intmain(void)
{
inti,t=0,sum=0;
for(i=9;i>=5;--i){
t=10*t+i;
sum+=t;
}
printf("%d ",sum);
return0;
}
B. C語言編程問題
g 首先是1,h是0,d是9,否則等式不可能成立的。
; z' X: v* j" U6 @. T6 D& _# A) ?a,b,c,e,f,i,j然後從2循環到8.# Y: O% \7 a) M7 c: u$ z8 I
共7層循環嵌套。
' G" F8 e4 r4 b6 K. f5 Q% E/ z最裡面一層判斷 a+b*10+c+9*100+e*10+f == 1*1000+0*100+i*10+j7 w5 E5 o% U7 F5 ^( O& L1 p" {6 H<br>如果相等,輸出每個表達式就可以了。 </p><p>代碼8 J" v6 j# R2 R9 e% T5 F6 P<br><br>2 N2 g2 r4 p0 m( ^#include "stdio.h"- ^3 D9 b7 T! p% W8 d<br>8 a4 A" N, r, e& O4 K0 u<br>main()<br># i. d7 g% ?9 W{<br>& a' {7 b8 H, @ int a,b,c,d=9,e,f,g=1,h=0,i,j,number=0;4 ]; Z7 v! \: f. s<br> int used[9]={0,0,0,0,0,0,0,0,0};
4 x/ g6 }; w- x, y3 S! c , l6 v* ?, R4 y. j( T
for (a=2;a<=8;a++){7 x ?/ J& Q7 n# F& z, W<br> used[a]=1;<br>! I' Q3 I6 }$ a; J5 Z for (b=2;b<=8;b++){
. ^5 D" I! {! I c) l: |# ^4 P if (!used[b]) P. z2 P5 t: u7 y9 N( c
{used[b]=1;6 q3 z4 g& O" r9 [ H' j<br> for (c=2;c<=8;c++){<br>9 C$ S# ~' T1 d6 p$ V: G: u5 e0 P if (!used[c])<br>( P5 K5 n g) x/ _ {used[c]=1;<br>1 X/ k# u) p2 A: c" c for (e=2;e<=8;e++){3 I% G& r8 F' c<br> if (!used[e])<br>+ x/ e2 C" `% ` {used[e]=1;<br>7 n1 C3 c( D: M5 P/ G* a% Q for (f=2;f<=8;f++){" t+ Y W$ |! P3 e<br> if (!used[f])3 y9 x# r1 N6 y4 V& x& l<br> {used[f]=1;; u, ]; M4 S7 z( k$ d<br> for (i=2;i<=8;i++){& |+ s' n$ ]2 o2 _9 m( q$ Q<br> if (!used[i])<br>! d) n3 M5 q0 R9 o- a) s {used[i]=1;<br>% Q6 d: v# J6 \. n4 t for (j=2;j<=8;j++)<br>' h1 r5 ~0 l; S if (!used[j]){ 0 v5 F( H! |8 A3 C<br> if (a+b*10+c+9*100+e*10+f == 1*1000+0*100+i*10+j)<br>4 E( v V: ^$ \: F j {number++;printf("%1d+%1d%1d+9%1d%1d =10%1d%1d\n",a,b,c,e,f,i,j);}}
2 u( f {$ q8 x) P% \ used[i]=0;
( R! C/ L; } C, ] }
2 F; S& g1 j8 [% S7 p( H+ y }
! g$ d$ g# q) K4 f used[f]=0;( w! _6 Q% D2 p3 M* F P! F" P% x
}' ~) W0 \6 J2 |3 i
}
: H# Z6 r c5 j" @ used[e]=0;4 `+ Z7 F" p! c
}5 W ] _7 r, m0 O2 s
}
$ |5 a: z/ O* H4 v8 s- P i used[c]=0;
1 h9 u7 [/ V# W! p6 H }
$ `4 U7 s' J4 L9 x$ q }
( S7 ], J* m6 Q! v used[b]=0;
: a# o- z8 Q+ F/ }! M }
5 R2 @% P$ m, h+ P }' o1 ^$ r; x9 T* n
used[a]=0;
( t" `3 \6 b! [ }, l6 w) L- }0 g) ]+ Z. M
printf("total statments number is %d\n",number);: N7 |5 Z+ k( v1 v- G
} 執行結果
6 Y: `0 r, X* V0 Y2+46+987 =1035
/ d" D% {# l9 V4 y$ a2+47+986 =1035, w4 e# x! d! r
2+64+987 =1053& Y. f, E+ F& E! c B1 g$ Y
2+67+984 =1053
: \, V; s- ^- C2+84+967 =1053
7 T' q: z" @. `1 x, x% W5 N2+86+947 =10352 `/ D. P: |; R
2+87+946 =1035
; t1 r1 b# s5 z+ T# h( l/ P$ ~2+87+964 =1053" O: W3 g( s2 F3 k$ P( E
3+45+978 =1026
3 S0 a3 S5 N3 ?' }" X3+48+975 =10260 I( A& d5 ^* }! L5 v7 \. {
3+74+985 =1062
- _6 z$ y7 t, X7 t9 t0 S3+75+948 =10265 T2 |! i2 N7 V1 [( Z% v) \' D1 P
3+75+984 =10625 Y4 \/ o& A8 } s' h
3+78+945 =10268 X* l! ^. N* u1 ~% y1 i
3+84+975 =1062
# X% D4 T7 W5 b: l; n! J" x3+85+974 =1062
1 c, V2 F# Y8 ]+ Y4+35+987 =1026
0 r% C' i. t& O4 H& `4+37+985 =1026
+ S. v8 ^9 B; m3 w: {4+62+987 =1053$ G- g7 d' E+ A u. ?6 h<br>4+67+982 =10532 k! s8 P+ m, `& w D4 @<br>4+73+985 =10620 n9 e3 \) {6 p) Y- q& X- n1 ?<br>4+75+983 =10629 \* U1 q L) |! t7 ]/ v9 b' x$ F9 y<br>4+82+967 =1053* b c- k3 h9 Z! E8 J4 y# a<br>4+83+975 =1062<br>3 ?2 c, E6 ?2 W8 p$ q& X. m4+85+937 =1026# {5 ^ V, D' T) s6 E) q; C* p& S<br>4+85+973 =1062<br>5 E6 f: O) R/ z' s1 m/ F4+87+935 =1026' x5 J4 A8 `0 r- w' |' |. ?<br>4+87+962 =1053% E. g# f+ f5 I* ~- s B<br>5+34+987 =1026<br>6 |) L" b& ~% ~9 ?& g+ ~- E5+37+984 =1026! t/ S7 A- y1 d+ S<br>5+43+978 =1026" n# D. R6 W- F3 f/ c: B<br>5+48+973 =1026" L% M# f, F4 N. p3 G! q4 U<br>5+73+948 =1026 @5 ~, A4 M0 w2 b+ n% J: y3 \8 l# [<br>5+73+984 =1062* Z- L/ V' w, s+ H1 D<br>5+74+983 =10624 Y K/ [+ q! T/ X<br>5+78+943 =1026<br>- h3 l9 z* t* }8 o5+83+974 =1062
* I; t* H7 K/ D( H& V9 v5+84+937 =1026- Z8 b; H5 X% @
5+84+973 =1062* x! p7 e# E. d& X2 M( t) t
5+87+934 =10261 p. A) _5 R7 m1 e+ i0 j
6+42+987 =1035
# H3 O# V+ f0 X0 } v+ K% ~6+47+982 =1035
1 B) X5 _' S$ k/ C9 J6+82+947 =10352 J' y4 F- W- z" h( ]
6+87+942 =1035
0 x; F" s4 L( l/ Q! V1 s7+34+985 =10268 O" w) w; V' |8 s A
7+35+984 =1026
& k" u" D3 G. p* e$ g# D% S( G4 X7+42+986 =10355 c s& @) I6 b( z+ m) C- n% k
7+46+982 =1035
" O* M' q! X0 X7 I7+62+984 =1053
, e( h, f& s3 g( b9 \7 L4 u7+64+982 =1053
) Q5 \5 e3 l: ?8 w; }5 W" t: e7+82+946 =1035
6 Y- w. e# \! B ]" b7+82+964 =1053+ U0 W: A/ f' i0 L/ \
7+84+935 =1026
- ?2 k- `- J/ J& q: g5 t$ s% _- ~7+84+962 =1053& e; f: v; B$ l$ Q9 o8 r& M) o
7+85+934 =1026
" F" p% m% S1 ~/ u, n- F7+86+942 =1035
) Q- W0 q9 I4 {. A2 y+ O. r8+43+975 =1026- i9 {* {6 ?( U( U<br>8+45+973 =1026+ s: Z4 }( p0 M* H
8+73+945 =10264 |* t3 z9 h V! D+ E
8+75+943 =10268 V8 A5 W( n: ]/ y6 o
total statments number is 60
C. C語言 字元串轉換
inti,j=0,sum=0;
charb[100],a[100];
scanf("%s",b);
for(i=0;b[i]!='