C语言练习题答æ¡?- 百度文库 ÏÂÔر¾ÎÄ

--------------------------------------53 54.

ÀûÓÃpi/2 = (2/1)*(2/3)*(4/3)*(4/5)*(6/5)*(6/7)*...Ç°100ÏîÖ®»ý£¬±à³Ì¼ÆËãpiµÄÖµ¡£

Ϊ±£Ö¤¼ÆË㾫¶È£¬ÇëÓÃdoubleÀàÐͼÆËã¡£ **Êä³ö¸ñʽҪÇó£º\

´ð°¸£º

#include main() {

doubled = 1, pi; inti, j;

for(i = 1; i <= 50; i++) for(j = 1; j <= 2; j++) {

if(j == 1)

d = d * (double)(i*2)/(i*2 - 1); else

d = d * (double)(i*2)/(i*2 + 1); } pi = 2*d;

printf(\ }

------------------------54 55.

ÀûÓæÐ4=1?13+15?17+¡­£¬±à³Ì¼ÆËã¦ÐµÄ½üËÆÖµ£¬Ö±µ½×îºóÒ»ÏîµÄ¾ø¶ÔֵСÓÚ10?4ʱΪֹ£¬Êä³ö¦ÐµÄÖµ²¢Í³¼ÆÀÛ¼ÓµÄÏîÊý¡£ **Êä³ö¸ñʽҪÇó£º\²ÉÓÃdouble¶¨ÒåÀۼӺͱäÁ¿

´ð°¸£º

#include intmain() {

doubled = 0, pi; inti, j = 0, k = 1;

for(i = 1;1 / (double)i >= 0.0001 || 1 /(double) i < -0.0001; i = i + 2) {

if(k % 2 == 0) {

d = d - 1 / (double)i; j++;

}

k++; } else {

d = d + 1 / (double)i; j++; k++; } }

d = d + 1/(double)i; j++;

pi = 4 * d;

printf(\

---------------------------------55 56.

´Ó¼üÅÌÊäÈë10¸öÕûÊý£¬±à³Ì¼ÆËã²¢Êä³öÆä×î´óÖµ¡¢×îСֵ¼°ÆäËùÔÚÔªËصÄϱêλÖá£

ÊäÈë¸ñʽ£º\

Êä³ö¸ñʽ£º\\ÊäÈëÑùÀý£º

1 2 3 4 5 6 7 8 9 10 Êä³öÑùÀý£º max=10, pos=9 min=1, pos=0

´ð°¸£º

#include main() {

inta[10] = {0}, j, i = 0, k = 0; intc, b;

for(j = 0; j < 10; j++) {

scanf(\ if(a[j] > i) {

i = a[j]; c = j; } if(j == 0) {

k = a[j]; b = j;

}

} elseif(a[j] < k) {

k = a[j]; b = j; } }

printf(\ printf(\

----------------56 57.

ðÅÝÅÅÐò£¨Bubble Sort£©£¬Ò²³ÆΪ³Á½µÅÅÐò£¨Sinking Sort£©£¬Ö®ËùÒÔ³ÆÆäΪðÅÝÅÅÐò£¬ÊÇÒòΪËã·¨ÖÐÖµÏà¶Ô½ÏСµÄÊý¾Ý»áÏñË®ÖеÄÆøÅÝÒ»ÑùÖð½¥ÉÏÉýµ½Êý×éµÄ×¶Ë¡£Óë´Ëͬʱ£¬½Ï´óµÄÊý¾ÝÖð½¥µØϳÁµ½Êý×éµÄµ×²¿¡£Õâ¸ö´¦Àí¹ý³ÌÐèÔÚÕû¸öÊý×鷶ΧÄÚ·´¸´Ö´Ðжà±é¡£Ã¿Ò»±éÖ´ÐÐʱ£¬±È½ÏÏàÁÚµÄÁ½¸öÔªËØ¡£Èô˳Ðò²»¶Ô£¬Ôò½«ÆäλÖý»»»£¬µ±Ã»ÓÐÊý¾ÝÐèÒª½»»»Ê±£¬Êý¾ÝÒ²¾ÍÅźÃÐòÁË¡£±à³Ì½«ÅÅÐòº¯ÊýDataSort()¸ÄÓÃðÅÝ·¨ÊµÏÖ¡£

**ÊäÈë¸ñʽҪÇó£º\ÌáʾÐÅÏ¢£º\**Êä³ö¸ñʽҪÇó£º\³ÌÐòÔËÐÐʾÀýÈçÏ£º Input n:10

Input 10 numbers: 2 9 3 4 0 6 8 7 5 1

Sorting results: 0 1 2 3 4 5 6 7 8 9

´ð°¸£º

#include

voidDataSort(inta[],intn); main() {

inta[100] = {0}, n,i = 0; printf(\ scanf(\

printf(\ do {

scanf(\ i++; }while(i < n); DataSort(a,n); }

voidDataSort(inta[],intn) {

intj, t, i;

for(i = 0;i < n; i++)

}

for(j = 1;j < n; j++)

if(a[j] < a[j - 1]) {

t = a[j-1]; a[j-1] = a[j]; a[j] = t; }

printf(\ for(i = 0; i < n; i++) printf(\

------------------------57 58.

ðÅÝÅÅÐò

²ÉÓÃðÅÝ·¨½øÐÐÉýÐòÅÅÐò·¨µÄ»ù±¾Ô­ÀíÊÇ£º¶ÔÊý×éÖеÄn¸öÊýÖ´ÐÐn-1±é¼ì²é²Ù×÷£¬ÔÚÿһ±éÖ´ÐÐʱ£¬¶ÔÊý×éÖÐÊ£ÓàµÄÉÐδÅźÃÐòµÄÔªËؽøÐÐÈçϲÙ×÷£º¶ÔÏàÁÚµÄÁ½¸öÔªËؽøÐбȽϣ¬ÈôÅÅÔÚºóÃæµÄÊýСÓÚÅÅÔÚÇ°ÃæµÄÊý£¬Ôò½»»»ÆäλÖã¬ÕâÑùÿһ±é²Ù×÷Öж¼½«²ÎÓë±È½ÏµÄÊýÖеÄ×î´óµÄÊý³Áµ½Êý×éµÄµ×²¿£¬¾­¹ýn-1±é²Ù×÷ºó¾Í½«È«²¿n¸öÊý°´´ÓСµ½´óµÄ˳ÐòÅźÃÐòÁË¡£ ³ÌÐòµÄij´ÎÔËÐнá¹ûÈçÏ£º Input n:10¨L

Input 10 numbers:2 9 3 4 0 6 8 7 5 1¨L

Sorting results: 0 1 2 3 4 5 6 7 8 9

ÊäÈë¸ñʽ:\Êä³ö¸ñʽ£º

ÊäÈëÊý¾Ý¸öÊýÌáʾ£º\

ÊäÈëÊý¾ÝÌáʾ£º\Êä³öÌáʾ£º\Êä³ö¸ñʽ£º\

´ð°¸£º

#include

voidDataSort(inta[], intn); main() {

inta[100] = { 0 }, n, i = 0; printf(\ scanf(\

printf(\ do {

scanf(\