闃呰涓嬪垪绋嬪簭璇存槑鍜孋浠g爜锛屽~鍏?n)澶勩€?/p>銆愯鏄庛€?/p>骞煎効鍥湁n(<20)涓瀛愬洿鎴愪竴鍦堝垎绯栨灉銆傝€佸笀鍏堥殢鏈哄湴鍙戠粰姣忎釜瀛╁瓙鑻ュ共

18 查阅

闃呰涓嬪垪绋嬪簭璇存槑鍜孋浠g爜锛屽~鍏?n)澶勩€?/p>

銆愯鏄庛€?/p>

骞煎効鍥湁n(<20)涓瀛愬洿鎴愪竴鍦堝垎绯栨灉銆傝€佸笀鍏堥殢鏈哄湴鍙戠粰姣忎釜瀛╁瓙鑻ュ共棰楃硸鏋滐紝

鐒跺悗鎸変互涓嬭鍒欒皟鏁达細姣忎釜瀛╁瓙鍚屾椂灏嗚嚜宸辨墜涓殑绯栨灉鍒嗕竴鍗婄粰鍧愬湪浠栧彸杈圭殑灏忔湅鍙嬨€傚鍏辨湁8涓瀛愶紝鍒欑1涓皢鍘熸湁鐨勪竴鍗婂垎缁欑2涓紝绗?涓皢鍘熸湁鐨勪竴鍗婂垎缁欑3涓紝鈥︹€︼紝绗?涓皢鍘熸湁鐨勪竴鍗婂垎缁欑1涓紝杩欐牱鐨勫钩鍒嗗姩浣滃悓鏃惰繘琛屻€傝嫢骞冲垎鍓嶏紝鏌愪釜瀛╁瓙鎵嬩腑鐨勭硸鏋滄槸濂囨暟棰楋紝鍒欏繀椤讳粠鑰佸笀閭i噷瑕佷竴棰楋紝浣夸粬鐨勭硸鏋滄暟鍙樻垚鍋舵暟銆傚皬瀛╀汉鏁板拰姣忎釜灏忓鐨勫垵濮嬬硸鏋滄暟鐢遍敭鐩樿緭鍏ャ€備笅闈㈢殑绋嬪簭鍙眰鍑虹粡杩囧灏戞涓婅堪杩欐牱鐨勮皟鏁达紝浣挎瘡涓瀛愭墜涓殑绯栨灉鈥旀牱澶氾紝璋冩暣缁撴潫鏃舵瘡涓瀛愭湁绯栨灉澶氬皯棰楋紝鍦ㄨ皟鏁磋繃绋嬩腑鑰佸笀鍙堟柊澧炲彂浜嗗灏戦绯栨灉銆?/p>

銆愮▼搴忋€?/p>

include

define N 20

int allEqual (int a[ ]锛宨nt n) /*妫€鏌ユ瘡涓瀛愭墜涓殑绯栨灉鏄惁涓€鏍峰*/

{ iht i;

for(i=1; in; i++)

if(a[O]!=a[i]) return O;

return 1;

}

int a[N], b[N];

void main ( )

{ int i, n, addk, loopc;

printf("Enter n((20)\n"); scanf("%d", &n);

printf ("Enter data\n");

for( i=O; i(n; i++) scanf("%d", &a[i]);

addk=O;(1);

while (2){ /*骞冲垎寰幆*/

loopc++;

for ( i=O; i ( n; i++){ /*涓轰竴娆¤皟鏁翠綔鍑嗗*/

if(a[i]%2) { a[i]++;(3); }

if (in-1) b[i+1]=a[i]/2; else(4)

a[i]/=2;

}

for(i=O; in; i++)(5); /*瀹屾垚涓€娆¤皟鏁?/

}

printf("璋冩暣%d娆n", loopc); printf("姣忎釜瀛╁瓙鏈?d棰楃硸鏋淺n", a[0]);

printf("璋冩暣杩囩▼涓柊澧炲彂%d棰楃硸鏋溿€俓n", addk); }

参考答案:

姝g‘绛旀锛?1)loopc=0 //loopc璁剧疆鍒濆€间负0(2)! a11Equal(a n) 鎴栬€?a11Equal (a n)==0 //鍒ゆ柇濂堜欢a11Equal (a n)鏄惁涓哄亣(3)addk++鎴栬€卆ddk=addk+1 //addk鐨勫€煎鍔?(4)b[0]=a[i]/2 //濡傛灉鏉′欢涓嶆弧瓒砨[0]鐨勫€兼槸a[i]/2(5)a[i]+=b[i]鎴栬€卆[i]=a[i]+b[i] //a[i]澧炲姞b[i](1)loopc=0 //loop