freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

c程序設(shè)計(jì)(第四版)(譚浩強(qiáng))完整版課后習(xí)題答案-文庫吧

2025-06-13 08:22 本頁面


【正文】 。 c=gcd(m,n)。 //c獲取最大公約數(shù) d=lcm(m,n)。 //d獲取最小公倍數(shù) printf(The GCD of %d and %d is : %d !\n, m, n, c)。 printf(The LCM of %d and %d is : %d !\n, m, n, d)。 return 0。}int gcd(int x, int y) //最大公約數(shù)Greatest Common Divisor{ int temp。 while(x%y!=0) { temp=y。 //y在下一輪中作為除數(shù),即是下一輪中的X,所以先閃一邊去. y=x%y。 //x,y的余數(shù)作為下一輪中的Y,由x%y來取得. x=temp。 //剛才temp中存儲(chǔ)了y的值,現(xiàn)在拿出來作為下一輪中的X使用. } return y。 //這是每一輪中的被除數(shù),按原理來,這就是最大公約數(shù),即累除法的原理.}int lcm(int x, int y) //最小公倍數(shù)Lowest Common Multiple{ int i, temp。 if(xy) //保證二者大的數(shù)在X上,大于號(hào)升序. { //以下為經(jīng)典三行碼,實(shí)現(xiàn)兩個(gè)數(shù)的互換. temp=x。 x=y。 y=temp。 } for(i=1。 i=y。 i++) //設(shè)定一個(gè)區(qū)間,從1至小的數(shù)之間的循環(huán). { if(!((x*i)%y)) //除得盡為零,非零為真,則成立并返回. { //如此往復(fù),直到取模無余數(shù),那么小的數(shù)X乘以區(qū)間當(dāng)前的I值,就是最小公倍數(shù). return x*i。 } }}最簡(jiǎn)單的C程序設(shè)計(jì)——順序程序設(shè)計(jì)P037 把華氏溫度轉(zhuǎn)化為攝氏表示法.include float F_to_C(float input_fah) //代表華轉(zhuǎn)攝,input_fah是局部變量.{ float output_cen。 //這里也是局部變量. output_cen=()*(input_fah32)。 //函數(shù)的功能體. return output_cen。 //返回值,注意,返回值的數(shù)據(jù)類型應(yīng)該和函數(shù)一致.}float C_to_F(float input_cen){ float output_fah。 output_fah=()*input_cen+32。 //轉(zhuǎn)換過程. return output_fah。}int main(){ int choice。 float input_fah,input_cen,output_fah,output_cen。 //局部變量的調(diào)用及參數(shù)傳遞. printf(F_to_C press 1 and C_to_F press 2 !\n)。 scanf(%d,amp。choice)。 if(choice==1) { printf(Please input fahrenheit :)。 scanf(%f,amp。input_fah)。 //這個(gè)是主函數(shù)定義的變量,雖然和調(diào)用函數(shù)同名.output_cen=F_to_C(input_fah)。 printf(The 華氏 is %d , 攝氏 is %d .,(int)input_fah,(int)output_cen)。 } if(choice==2) { printf(Please input centigrade :)。 scanf(%f,amp。input_cen)。 output_fah=C_to_F(input_cen)。 printf(The Centigrade is %d , and the Fahrenheit is %d .,(int)input_cen,(int)output_fah)。 } return 0。}P038 計(jì)算存款利息(關(guān)于精度問題).include int main(){ float p0=1000,r1=,r2=,r3=,p1,p2,p3。 p1=p0*(1+r1)。 p2=p0*(1+r2)。 p3=p0*(1+r3/2)*(1+r3/2)。 printf(p1=%f\np2=%f\np3=%f\n,p1,p2,p3)。 return 0。}P055 大寫轉(zhuǎn)換成小寫include int main() //小寫范圍是97122,大寫范圍是6590,.{ char c1, c2。 c1=39。A39。 c2=c1+32。 printf(%c %d,c2,c2)。 return 0。}P059 給出三角形邊長(zhǎng),算出面積.include include int main() { double a=, b=, c=, s, area。 s=(a+b+c)/2。 area=sqrt(s*(sa)*(sb)*(sc))。 printf(area is %f\n,area)。 //默認(rèn)可以組成三角形. return 0。}P065 求一無二次等式的根,默認(rèn)兩個(gè)不同根.include include int main() { double a,b,c,disc,x1,x2,p,q。 scanf(%lf %lf %lf,amp。a,amp。b,amp。c)。 disc=b*b4*a*c。 p=b/(*a)。 q=sqrt(disc)/(*a)。 x1=p+q。 x2=pq。 printf(x1=%\nx2=%,x1,x2)。 return 0。}P071 用%f輸出實(shí)數(shù),只能得到六位小數(shù).include include int main() { double a=。 //1是整型,. printf(%.9f\n,a/3)。 return 0。}P072 float型數(shù)據(jù)的有效位數(shù).include include int main(){ float a。 //,float精度6位,所以第七位后不可信. a=10000/。 printf(%f\n,a)。 return 0。}P078 使用putchar函數(shù)輸出.include include int main(){ char a=39。B39。,b=39。O39。,c=39。Y39。 putchar(a)。 putchar(b)。 putchar(c)。 putchar(39。\n39。)。 putchar(101)。 //101是A的ASCII代碼的縮寫,因?yàn)榇撕瘮?shù)只能輸出字符. putchar(66)。 return 0。}P079 使用getchar得到字符.include include int main(){ char a,b,c。 a=getchar()。 b=getchar()。 c=getchar()。 putchar(a)。 putchar(b)。 putchar(c)。 //這也是基本回顯的C程序代碼. putchar(39。\n39。)。 return 0。}P081 getchar得到大寫,putchar輸出小寫.include include int main(){ char a,b。 a=getchar()。 b=a+32。 putchar(b)。 putchar(39。\n39。)。 return 0。}P082 國(guó)民生產(chǎn)總值10年后的增長(zhǎng)倍數(shù).include include int main(){ double p,r=,n=10。 p=pow((1+r),n)。 //這是數(shù)學(xué)函數(shù), pow(x,y)計(jì)算x的y次方. printf(P is %lf when 10 years later .\n,p)。 return 0。 //.}P082 求各種存款的利息數(shù).include include int main(){ double p,r,n。 //年份和當(dāng)年利率均有給出. p=1000*(1+5*)。 printf(5 years is %lf !\n,p)。 //,. p=(1000*(1+2*))。 p=(p*(1+3*))。 printf(5 years is %lf !\n,p)。 //,這是先二年,再三年的. p=(1000*(1+3*))。 p=(p*(1+2*))。 printf(5 years is %lf !\n,p)。 //,這是先三年,是一樣的. p=1000*pow((1+),5)。 printf(5 years is %lf !\n,p)。 //,這難道說是,相對(duì)的存死期越久越值錢. p=1000*pow((1+),4*5)。 printf(5 years is %lf !\n,p)。 //. return 0。 }P083 求幾個(gè)月要以還貸.include include int main(){ double m,r=,d=300000,p=6000。 m=(log10(p/(pd*r)))/(log10(1+r))。 printf(%.1lf,m)。 //按要求只留一個(gè)小數(shù),所以要寫%.1lf. return 0。}P084 字母密碼轉(zhuǎn)換,調(diào)用函數(shù)及臨界處理.include char printcode(char f){ if(((int)f86amp。amp。(int)f91)||((int)f118amp。amp。(int)f123)) { return(f26+4)。 //因?yàn)閜utchar會(huì)自動(dòng)返回,所以改成return,因?yàn)檫@是在函數(shù)中,調(diào)用需要返回值. } else { return(f+4)。 }}int main(){ char a,b,c,d,e。 printf(Please input :\n)。 a=getchar()。 b=getchar()。 c=getchar()。 d=getchar()。 e=getchar()。 //臨界問題. printf(%c%c%c%c%c,printcode(a),printcode(b),printcode(c),printcode(d),printcode(e))。 putchar(putcharcode(a))。 putchar(putcharcode(b))。 putchar(putcharcode(c))。 putchar(putcharcode(d))。 putchar(putcharcode(e))。 return 0。 //注意理解自定義函數(shù)的定義,使用,及形參實(shí)參的流向. //p84的是計(jì)算問題,自己看著辦,最后要求小數(shù)點(diǎn)后兩位,用的是%.2lf 來實(shí)現(xiàn),因?yàn)闆]有要求實(shí)部,. //p84的是定義問題,第一問,兩者都行,但是定義字母時(shí),scanf要寫%c來獲取,而定義數(shù)值時(shí)則要用%d來獲取. // 第二問,putchar貌似只能輸出字符,字符,有木有!!!字符啊!!盡管它的參數(shù)可以是putchar(39。\10139。),效果是輸出字符A啊. // 第三問,出現(xiàn)任何及無條件,那么答案明顯是否.可以轉(zhuǎn)換,但要在某此條件下,例如輸出和讀入時(shí),%c是字母,而%d是數(shù)值,看著辦.}選擇結(jié)構(gòu)程序設(shè)計(jì)P086 一無二次方程求根的二分支.include include int main() { double a,b,c,disc,x1,x2,p,q。 scanf(%lf %lf %lf,amp。a,amp。b,amp。c)。 disc=b*b4*a*c。 if(disc0) //這是選擇結(jié)構(gòu)和其判斷條件的示例. printf(This equation hasn39。t real roots\n)。 else { p=b/(*a)。 q=sqrt(disc)/(*a)。 x1=p+q。 x2=pq。 printf(x1=%\nx2=%,x1,x2)。 } return 0。}P087 二個(gè)數(shù)按大小輸出.include int main() //此程序代表按大小順序輸出.{ float a,b,t。 scanf(%f %f,amp。a,amp。b)。 //出錯(cuò)時(shí),. if(ab) { t=a。 a=b。 b=t。 } printf(%,%\n,a,b)。 return 0。}P088 三個(gè)數(shù)按大小輸出.include int
點(diǎn)擊復(fù)制文檔內(nèi)容
法律信息相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1