【正文】
intf(Price: \n)。 } return 0。}數(shù)據(jù)區(qū)間判斷(5分)題目內(nèi)容:從鍵盤輸入一個int型的正整數(shù)n(已知:0n10000),編寫程序判斷n落在哪個區(qū)間。如果用戶輸入的數(shù)據(jù)不在指定的范圍里,程序輸出 error!。例如,輸入265,則該數(shù)屬于區(qū)間 100999。程序運(yùn)行結(jié)果示例1:Please enter the number:2563↙2563: 10009999程序運(yùn)行結(jié)果示例2:Please enter the number:156↙156: 100999程序運(yùn)行結(jié)果示例3:Please enter the number:36↙36: 1099程序運(yùn)行結(jié)果示例4:Please enter the number:3↙3: 09程序運(yùn)行結(jié)果示例5:Please enter the number:10923↙error!輸入格式:%d輸出格式:輸入提示信息:Please enter the number:\n輸出的區(qū)間判斷:%d: 10009999\n%d: 100999\n%d: 1099\n%d: 09\n輸入錯誤提示信息:error!\n輸入樣例:輸出樣例:includeincludeint main(){ int x。 printf(Please enter the number:\n)。 scanf(%d,amp。x)。 if (x=1000amp。amp。x=9999) printf(%d: 10009999\n,x)。 else if (x=0amp。amp。x=9) printf(%d: 09\n,x)。 else if (x=10amp。amp。x=99) printf(%d: 1099\n,x)。 else if (x=100amp。amp。x=999) printf(%d: 100999\n,x)。 else printf(error!\n)。 return 0。}(3分)題目內(nèi)容:根據(jù)下面給出的求根公式,計算并輸出一元二次方程的兩個實根,要求精確到小數(shù)點后4位。其中a,b,c的值由用戶從鍵盤輸入。如果用戶輸入的系數(shù)不滿足求實根的要求,輸出錯誤提示error!。程序運(yùn)行結(jié)果示例1:Please enter the coefficients a,b,c:1,2,1↙x1=, x2=程序運(yùn)行結(jié)果示例2:Please enter the coefficients a,b,c:2,6,1↙x1=, x2=程序運(yùn)行結(jié)果示例3:Please enter the coefficients a,b,c:2,1,6↙error!輸入格式:%f,%f,%f輸出格式:輸入提示信息:Please enter the coefficients a,b,c:\n輸出格式:x1=%, x2=%\n輸入錯誤提示信息:error!\n輸入樣例:輸出樣例:includeincludeint main(){ float a,b,c,x1,x2,m。 printf(Please enter the coefficients a,b,c:\n)。 scanf(%f,%f,%f,amp。a,amp。b,amp。c)。 m=b*b4*a*c。 if (m0){ printf(error!\n)。 } else{ x1=(b+sqrt(m))/(2*a)。 x2=(bsqrt(m))/(2*a)。 printf(x1=%, x2=%\n,x1,x2)。 } return 0。}第五章6位密碼輸入檢測(3分)題目內(nèi)容:從鍵盤輸入6位僅由數(shù)字0~9組成的密碼。用戶每輸入一個密碼并按回車鍵后,程序給出判斷:如果是數(shù)字,則原樣輸出該數(shù)字,并提示用戶目前已經(jīng)輸入了幾位密碼,同時繼續(xù)輸入下一位密碼;否則,程序提示error,并讓用戶繼續(xù)輸入下一位密碼。直到用戶輸入的密碼全部是數(shù)字為止。以下為程序的運(yùn)行結(jié)果示例:Input your password:1↙1, you have enter 1bits number6↙6, you have enter 2bits numbera↙errord↙error4↙4, you have enter 3bits number6↙6, you have enter 4bits number8↙8, you have enter 5bits number2↙2, you have enter 6bits number輸入格式:數(shù)字字符輸入格式:%c輸出格式:輸入提示信息:Input your password:\n如果輸入的是數(shù)字,輸出格式為:%c, you have enter %dbits number\n如果輸入的不是數(shù)字,輸出提示信息:error\n輸入樣例:輸出樣例:include int main(){ char a。 int i=0。 printf(Input your password:\n)。 while(i6) { scanf(%c,amp。a)。 if (a=48amp。amp。a=57) { printf(%c, you have enter %dbits number\n,a,++i)。 } else printf(error\n)。 getchar()。 } return 0。}(4分)題目內(nèi)容:從鍵盤輸入一個整型數(shù)據(jù)(int型),編寫程序判斷該整數(shù)共有幾位。例如,從鍵盤輸入整數(shù)16644,該整數(shù)共有5位。程序運(yùn)行結(jié)果示例1:Please enter the number:21125↙21125: 5 bits程序運(yùn)行結(jié)果示例2:Please enter the number:12234↙12234: 5 bits輸入格式:%d輸出格式:輸入提示信息:Please enter the number:\n判斷該整數(shù)共有幾位:%d: %d bits\n輸入樣例:輸出樣例:include int main(){ int x,y,n。 printf(Please enter the number:\n)。 scanf(%d,amp。x)。 n=x。 for(y=1。x/=10。y++)。 printf(%d: %d bits\n,n,y)。 return 0。}檢測輸入數(shù)據(jù)中奇數(shù)和偶數(shù)的個數(shù)(4分)題目內(nèi)容:從鍵盤輸入一系列正整數(shù),輸入1表示輸入結(jié)束(1本身不是輸入的數(shù)據(jù))。編寫程序判斷輸入數(shù)據(jù)中奇數(shù)和偶數(shù)的個數(shù)。如果用戶輸入的第一個數(shù)據(jù)就是1,則程序輸出over!。否則。用戶每輸入一個數(shù)據(jù),輸出該數(shù)據(jù)是奇數(shù)還是偶數(shù),直到用戶輸入1為止,分別統(tǒng)計用戶輸入數(shù)據(jù)中奇數(shù)和偶數(shù)的個數(shù)。程序運(yùn)行結(jié)果示例1:Please enter the number:1↙1:odd5↙5:odd8↙8:even9↙9:odd12↙12:even17↙17:odd1↙The total number of odd is 4The total number of even is 2程序運(yùn)行結(jié)果示例2:Please enter the number:1↙over!The total number of odd is 0The total number of even is 0輸入格式:%d輸出格式:輸入提示信息:Please enter the number:\n用戶輸入的第一個數(shù)據(jù)就是1,輸出格式:over!\n奇數(shù)的輸出格式:%d:odd\n偶數(shù)的輸出格式:%d:even\n輸入數(shù)據(jù)中奇數(shù)的個數(shù)統(tǒng)計:The total number of odd is %d\n輸入數(shù)據(jù)中偶數(shù)的個數(shù)統(tǒng)計:The total number of even is %d\n輸入樣例:輸出樣例:include int main(){ int s,odd=0,even=0。 printf(Please enter the number:\n)。 do{ scanf(%d,amp。s)。 if (s==1amp。amp。odd==0amp。amp。even==0) printf(over!\n)。 else if( s%2!=0 amp。amp。s!=1) {printf(%d:odd\n,s)。odd++。} else if (s%2==0){printf(%d:even\n,s)。even++。} else even+=0。 }while (s!=1)。 printf(The total number of odd is %d\n,odd)。 printf(The total number of even is %d\n,even)。 return 0。}計算球的反彈高度(4分)題目內(nèi)容:一個球從100米高度自由落下,每次落地后反跳回原高度的一半,再落下并反彈......,求它在第5次和第10次落地時,分別共經(jīng)過了多少米?第5次和第10次反彈分別是多高?要求計算結(jié)果保留到小數(shù)點后3位。用戶從鍵盤輸入想要計算的第n次(n=15)。程序運(yùn)行結(jié)果示例1:input:5↙5 times:程序運(yùn)行結(jié)果示例2:input:10↙10 times:輸入格式:%d輸出格式:反彈次數(shù):%d times:\n第n次反彈共經(jīng)過多少米:%.3f\n第n次的反彈高度:%.3f\n輸入提示信息:input:\n輸入樣例:輸出樣例:include int main(){ int time,i。 float each=0,sum=0,h=100。 printf(input:\n)。 scanf(%d,amp。time)。 for (i=0。itime。i++){ sum+=h。 h/=2。 each=h。 sum+=each。 } printf(%d times:\n,time)。 printf(%.3f\n,sumeach)。 printf(%.3f\n,each)。 return 0。}第六章(5分)下面代碼的功能是將百分制成績轉(zhuǎn)換為5分制成績,具體功能是:如果用戶輸入的是非法字符或者不在合理區(qū)間內(nèi)的數(shù)據(jù)(例如輸入的是a,或者102,或45等),則程序輸出Input error!,并允許用戶重新輸入,直到輸入合法數(shù)據(jù)為止,并將其轉(zhuǎn)換為5分制輸出。目前程序存在錯誤,請將其修改正確。并按照下面給出的運(yùn)行示例檢查程序。1. include2. intmain()3. {4. intscore。5. chargrade。6. printf(Pleaseinputscore:)。7. scanf(%d,amp。score)。8. if(score0||score100)9. printf(Inputerror!\n)。10. elseif(score=90)11. grade=39。A’。12. elseif(score=80)13. grade=39。B39。14. elseif(score=70)15. 1