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

正文內(nèi)容

c程序設(shè)計(jì)(第四版)(譚浩強(qiáng))完整版課后習(xí)題答案(編輯修改稿)

2024-07-25 08:22 本頁(yè)面
 

【文章內(nèi)容簡(jiǎn)介】 main() //此程序代表按大小順序輸出.{ float a,b,c,t。 scanf(%f %f %f,amp。a,amp。b,amp。c)。 if(ab) //此處執(zhí)行后,a為小者. { t=a。 a=b。 b=t。 } if(ac) //此處執(zhí)行后,a為小者. { t=a。 a=c。 c=t。 } if(bc) //上面已經(jīng)搞定a是最小者,現(xiàn)在對(duì)比得出次小者,并且已經(jīng)歸到變量中. { t=b。 b=c。 c=t。 } printf(%,%%\n,a,b,c)。 return 0。}P099 判斷輸入字符,并最終按小寫(xiě)輸出.include int main(){ char ch。 scanf(%c,amp。ch)。 ch=(ch=39。A39。amp。amp。ch=39。Z39。)?(ch+32):ch。 //條件運(yùn)算符,真取前,假取后. printf(%c\n,ch)。 return 0。}P100 按要求輸出相應(yīng)的Y值.include int main(){ int x,y。 scanf(%d,amp。x)。 if(x=0) { if(x0) //這個(gè)范圍要基于x=0來(lái)判斷. { y=1。 } else { y=0。 } } else //這個(gè)是x0的范圍. { y=1。 } printf(x=%d,y=%d,x,y)。 return 0。}P102 switch的簡(jiǎn)單應(yīng)用.include int main(){ char grade。 scanf(%c,amp。grade)。 printf(Your score:)。 switch(grade) { case39。a39。:printf(85100\n)。break。 //當(dāng)多分支結(jié)構(gòu)過(guò)于多時(shí),可以用switch來(lái)解決. case39。b39。:printf(7084\n)。break。 case39。c39。:printf(6069\n)。break。 case39。d39。:printf(60\n)。break。 default:printf(Enter data error!\n)。 } return 0。}P104 按輸入執(zhí)行操作,并且不分大小寫(xiě).include void action1(int x,int y){ printf(x+y=%d\n,x+y)。}void action2(int x,int y){ printf(x*y=%d\n,x*y)。}int main(){ char ch。 int a=15,b=23。 ch=getchar()。 switch(ch) { case39。a39。: case39。A39。:action1(a,b)。break。 //a,A共用一個(gè)執(zhí)行語(yǔ)句. case39。b39。: case39。B39。:action2(a,b)。break。 default:putchar(39。\a39。)。 //39。\a39??梢钥刂齐娔X發(fā)出蜂鳴聲. } return 0。}P106 用if的分支來(lái)做閏年問(wèn)題include int main(){ int year,leap。 printf(Please input the year:\n)。 scanf(%d,amp。year)。 if(year%4==0) //400年里,在100個(gè)可除盡4的年里計(jì)算,以下是在全范圍內(nèi)計(jì)算. { if(year%100==0) //既是100個(gè)內(nèi)的,又是可以除盡100的,算是且. { if(year%400==0) //相當(dāng)于且了兩次,只余下唯一一個(gè). { leap=1。 } else //400年里只有1個(gè)除得盡,其它都不是. { leap=0。 } } else //這里的范圍是(year%4==0)amp。amp。(year%100!=0) { leap=1。 //在合法的100內(nèi),又不是2100,2200一類的,當(dāng)然屬閏年. } } else { leap=0。 } if(leap) { printf(%d is ,year)。 } else { printf(%d is not ,year)。 } printf(a leap year !)。 //不管上面如何判斷,最后還是會(huì)輸出這一句. return 0。}P108 一元二次等式的全計(jì)算過(guò)程.include include int main(){ double a,b,c,disc,x1,x2,realpart,imagpart。 scanf(%lf %lf %lf,amp。a,amp。b,amp。c)。 printf(The equation )。 if(fabs(a)=1e6) //fabs是絕對(duì)值, le6,即是的負(fù)六次方,接近或是等于零. { printf(is not a quadratic !\n)。 printf(x1=x2=%lf,c/b)。 } else { disc=b*b4*a*c。 if(fabs(disc)=1e6) //指數(shù)形式,數(shù)字1. { printf(has two equal roots : %lf\n,b/(2*a))。 } else { if(disc1e6) { x1=(b+sqrt(disc))/(2*a)。 x2=(bsqrt(disc))/(2*a)。 printf(has distinct real roots : %lf and %lf \n,x1,x2)。 } else { realpart=b/(2*a)。 imagpart=sqrt(disc)/(2*a)。 printf(has plex roots: \n)。 printf(%lf + %lfi\n,realpart,imagpart)。 printf(%lf + %lfi\n,realpart,imagpart)。 } } } return 0。}P109 關(guān)于多個(gè)區(qū)間的計(jì)算,運(yùn)費(fèi)問(wèn)題為例.include int main(){ double p,w,s,d,f。 printf(p,w,s\n)。 scanf(%lf %lf %lf,amp。p,amp。w,amp。s)。 if(s250) { d=。 f=p*w*s*(1d)。 printf(%lf,f)。 } else if(s500) { d=。 f=p*w*s*(1d)。 printf(%lf,f)。 } else if(s1000) { d=。 f=p*w*s*(1d)。 printf(%lf,f)。 } else if(s2000) { d=。 f=p*w*s*(1d)。 printf(%lf,f)。 } else if(s3000) { d=。 f=p*w*s*(1d)。 printf(%lf,f)。 } else { d=。 f=p*w*s*(1d)。 printf(%lf,f)。 } return 0。}P0112 鍵盤(pán)輸入三個(gè)數(shù),輸出最大者.include int mina,mida,maxa。int max(int a,int b,int c){ int m。 if(ab) //凡是比較中,大于號(hào)代表升序排列. { m=a。 a=b。 b=m。 } if(ac) { m=a。 a=c。 c=m。 } if(bc) { m=a。 a=c。 c=m。 } return (c)。 //此排序后,a,b,.}int main(){ int a,b,c。 printf(Please input 3 numbers :)。 scanf(%d %d %d,amp。a,amp。b,amp。c)。 printf(The max is %d !\n,max(a,b,c))。 return 0。} P0112 一個(gè)小于1000的數(shù),有判定條件.include include int main(){ double a,b。 printf(Please input a number :)。 scanf(%lf,amp。a)。 if(a1000) { b=sqrt(a)。 } else { printf(\a)。 //控制蜂鳴聲 printf(Please input a number again :)。 scanf(%lf,amp。a)。11 b=sqrt(a)。 } printf(%.0lf,b)。 //按要求,只取整數(shù). return 0。}P0112 一個(gè)不多于5位的數(shù),按條件輸出.include include int main(){ int i,a,b[4],count=0。 printf(Please input a number (fivedigit number) :)。 //意思是五位數(shù)以內(nèi). scanf(%d,amp。a)。 for(i=0。i=4。i++) { b[i]=a%10。 //是%10,不是/10000,結(jié)果就是b[0]至b[4]中存著個(gè),十,百,千,萬(wàn)位. a=a/10。 // /10后得到的結(jié)果去掉了個(gè)數(shù). if(b[i]!=0) { count=count+1。 } } printf(%d位數(shù).\n,count)。 printf(分別輸出每一位數(shù)字,如下:)。 for(i=4。i=0。i) { printf(%d ,b[i])。 } printf(\n)。 printf(倒序輸出這一個(gè)數(shù)字,如下:)。 for(i=0。i=4。i++) { printf(%d,b[i])。 } printf(\n)。 return 0。 } P0112 按要求提成獎(jiǎng)金(if寫(xiě)法).include int main(){ double a,b。 printf(Please input profit amount :)。 scanf(%lf,amp。a)。 if(a=10) //這個(gè)是整個(gè)if 的基礎(chǔ). { b=a*。 } else if(a=20) //以上面為基礎(chǔ),這已經(jīng)代表了1020間了!!! { b=1+(a10)*。 } else if(a=40) //同理,這是2040間. { b=1++(a20)*。 } else if(a=60) { b=1+++(a40)*。 } else if(a=100) { b=1++++(a60)*。 } else //這里是大于100的. { b=1++++(a100)*。 } printf(The reward is %lf !\n,b)。 return 0。} P0112 按要求提成獎(jiǎng)金(switch寫(xiě)法).include double GetProfit(double c) { printf(Please input profit amount :)。 scanf(%lf,amp。c)。 return (c)。 //返回本身了,如果有進(jìn)一步的計(jì)算結(jié)果,將值賦給其它變量,也可以返回.}int main(){ double a。 char c。 printf(Your choice :\nA : 010 。\nB : 1020 。\nC : 2040 。\nD : 4060 。\nE : 60100 。\nF : 1001000 。\n)。 scanf(%c,amp。c)。 //不同檔時(shí),應(yīng)照檔的規(guī)定數(shù)值進(jìn)行輸入,否則結(jié)果不會(huì)是正確的. switch(c) //前三后三用于比較調(diào)用函數(shù). { //GetProfit(c)引入的實(shí)參沒(méi)有意義,返回值和引入的實(shí)參沒(méi)關(guān)系,反而由鍵盤(pán)獲得. case39。A39。:{ printf(The reward is %lf !\n,GetProfit(c)*)。}
點(diǎn)擊復(fù)制文檔內(nèi)容
法律信息相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖片鄂ICP備17016276號(hào)-1