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

正文內(nèi)容

語言程序設(shè)計練習題2(編輯修改稿)

2025-10-13 18:50 本頁面
 

【文章內(nèi)容簡介】 utput 1 2 3HINT Append Code include void main(){int a,b,c,temp。scanf(”%d%d%d“,amp。a,amp。b,amp。c)。if(a{temp=a。a=b。b=temp。}if(a{temp=a。a=c。c=temp。}if(b{temp=b。b=c。c=temp。}printf(”%d %d %dn“,c,b,a)。} E: Description 判斷輸入整數(shù)的奇偶性。判斷奇偶數(shù) Input 輸入為一個整數(shù)。Output 輸出只有一行,代表判斷結(jié)果。如果輸入的整數(shù)n是一個偶數(shù),輸出: n is an even :n is an odd 。Sample Input 12Sample Output 12 is an even Append Code include int main(){int a。scanf(”%d“,amp。a)。if(a%2==0)printf(”%d is an even number.“,a)。elseprintf(”%d is an odd number.“,a)。} A: 判斷兩個整數(shù)的大小關(guān)系 Description 輸入2個整數(shù)a和b,如果ab,則輸出1,否則輸出0。Input 兩個整數(shù)a和b,均不超過int類型的表示范圍。Output 表示ab的結(jié)果:如果ab,則輸出1,否則輸出0。Sample Input 3 4Sample Output 0HINTAppend Code include int main(){ int a,b。scanf(”%d %d“,amp。a,amp。b)。if(ab)printf(”1“)。elseprintf(”0“)。return 0。} D: 成績的等級 Description 把百分制的考試成績轉(zhuǎn)換成五級制的成績: 90~100:Excellent 80~89:Good 70~79:Average 60~69:Pass 0~59:Failing不在0~100之間的輸入是非法數(shù)據(jù),輸出“Error”。Input 輸入多行,每行一個整數(shù)。Output 輸入所對應的成績等級。Sample Input1 81 92 35 68 72 100Sample Output Error Good Excellent Failing Pass Average Excellent HINT 用switch語句解決這個問題比較方便。Append Code include int main(){int score。while(scanf(”%d“,amp。score)!=EOF){if(score100)printf(”Errorn“)。else{switch(score/10){case 0:case 1:case 2:case 3:case 4:case 5:printf(”Failingn“)。break。case 6:printf(”Passn“)。break。case 7:printf(”Averagen“)。break。case 8:printf(”Goodn“)。break。case 9:case 10:printf(”Excellentn“)。break。}}}return 0。} E: 輸出是m的倍數(shù)或n的倍數(shù)、但不是m和n的公倍數(shù)的數(shù) Description 輸出1~k之間是m的倍數(shù)或n的倍數(shù)、但不是m和n的公倍數(shù)的數(shù),其中1Input 輸入三個整數(shù),依次為k、m、n。Output 從小到大輸出符合題意的所有整數(shù),兩數(shù)之間用一個空格分開。Sample Input 15 2 3Sample Output 2 3 4 8 9 10 14 15HINT 難點在于輸出格式的控制:空格在數(shù)的中間,學會用循環(huán)時邊界情況的特殊處理。Append Code include int main(){ int k,m,n,a,i=1。scanf(”%d %d %d“,amp。k,amp。m,amp。n)。if(ma=m。elsea=n。printf(”%d“,a)。for(i=a+1。i}if((i%m==0amp。amp。i%n!=0)||(i%n==0amp。amp。i%m!=0))printf(” %d“,i)。} return 0。 B: 兩整數(shù)相加減 Description 計算a+b和ab。Input 輸入為一對整數(shù)a和b。a,b用空格分開。Output 輸出a+b和ab的計算結(jié)果,各占一行。Sample Input 1 2Sample Output 31HINT Append Code include int main(){ int a,b。scanf(”%d %d“,amp。a,amp。b)。printf(”%dn“,a+b)。printf(”%dn“,ab)。} 25 Problem C: 它滿足條件嗎? Description 需要判斷給定的一個整數(shù)是否同時滿足如下三個條件: 。注:若一個數(shù)能表示成某個自然數(shù)的平方的形式,則稱這個數(shù)為完全平方數(shù)。例如:0,1,4,9,16,25,36,49,64,81,100,121,144,169,196,225,256,289,324,361,400,441,484,529 Input 一個int范圍內(nèi)的整數(shù)。Output 如果輸入的數(shù)字滿足條件,則輸出yes,否則輸出no。Sample Input 100Sample Output yesHINT 注意邏輯表達式判斷三個條件的順序。如果你不會使用分支語句,同樣可以使用條件運算符實現(xiàn)該程序。庫函數(shù)sqrt()可以用于求一個數(shù)的平方根。Append Code include include int main(){ int a。scanf(”%d“,amp。a)。if(a==sqrt(a)*sqrt(a)amp。amp。a%2==0amp。amp。a0)printf(”yes“)。elseprintf(”no“)。} F: 多路分支 Description 編寫一個完整的程序,運行時向用戶提問”你考試考了多少分?(0100)“接受輸入后判斷其等級并顯示出來等級: 優(yōu):90Input 輸入任意一個整數(shù)分數(shù)值,顯示等級。再輸入任意一個整數(shù)分數(shù)值,顯示等級。....直到測試數(shù)據(jù)較充分,可輸入1止。Output 對任意輸入的分數(shù)值,輸出對應的等級, Input 102 100 90 80 70 60 50 0801Sample Output grad must between 0 and 100 優(yōu)優(yōu)良中中差差grad must between 0 and 100 grad must between 0 and 100HINT Append Code include int main(){int x。while(scanf(”%d“,amp。x)!=EOF){if(x100)printf(”grad must between 0 and 100n“)。else if(x=90)printf(”優(yōu)n“)。else if(x=80)printf(”良n“)。else if(x=60)printf(”中n“)。else if(x=0)printf(”差n“)。}return 0。} Problem D: 有多少人? Description 學校舉行運動會,如果全體學生按照3人一隊列隊,則多了1個人;如果按照4人一隊列隊,則多了2個人;如果按照5人一隊排隊,則多了3個人。請問這個學校有多少學生?Input 一個int類型的正整數(shù)N,是學生人數(shù)的上界,即:該校學生數(shù)不超過N。Output 所有可能的學生數(shù),每個數(shù)占一行。Sample Input 200Sample Output 58 118 178HINT Append Code include include int main(){int n,i。scanf(”%d“,amp。n)。for(i==1。iprintf(”%dn“,i)。}return 0。} Problem C: 正負數(shù)各有幾個? Description 輸入若干個整數(shù),求其中正數(shù)、負數(shù)的個數(shù)。Input 輸入分為2行:第一行是一個數(shù)字N0,表示下面有N個整數(shù)。第2行是N個整數(shù),都是int類型的。Output 輸出所輸入的N個整數(shù)的正數(shù)個數(shù)和負數(shù)個數(shù),并用空格分開2個輸出。Sample Input 10 2 3 4 512345Sample Output 5 5HINT 貌似還有一種叫做0的數(shù)。Append Code include int main(){int n,a,i,num1=0,num2=0。scanf(”%d“,amp。n)。for(i=0。i{scanf(”%d“,amp。a)。if(a0)num1++。else if(anum2++。}printf(”%d %dn“,num1,num2)。return 0。} Problem A: A+B Problem(III): Input/OutputPractice Description 計算a+b,0Input 輸入有多對整數(shù)a和b組成,每對a和b占一行,a,b用空格分開。當測試樣為0 0時表示輸入結(jié)束,0 0不參與運算。Output 每行輸出一個a+b的值,順序與輸入對應。Sample Input 1 2 10 20 0 0Sample Output 3 30HINT 練習break的使用。Append Code include int main(){ int a,b。while(scanf(”%d %d“,amp。a,amp。b)!=EOF){if(a!=0||b!=0)}printf(”%dn“,a+b)。elsebreak。return 0。} 30 Problem B: A+B Problem(IV): Input/OutputPractice Description 計算a+b,0Input 輸入有多對整數(shù)a和b組成,每對a和b占一行,a,b用空格分開。Output 每行輸出一個a+b的值,順序與輸入對應。每個格式樣例之間用一個空行分隔開。Sample Input 1 2 10 20 15 35Sample Output 3 30 50HINT 由于輸出的和比空行多一個,所以全部計算放在一個循環(huán)里是不行的,必須要特殊處理開頭或者結(jié)尾。Append Code include int main(){ int a,b,n=0。while(scanf(”%d %d“,amp。a,amp。b)!=EOF){n++。if(n==1)printf(”%dn“,a+b)。elseprintf(”n%dn“,a+b)。}return 0。}Problem C: n個數(shù)的最大值和最小值 Description 找出n個數(shù)中最大的數(shù)和最小的數(shù),并將它們的值輸出出來。Input 輸入為n+1個整數(shù),都在int類型范圍內(nèi)。這些數(shù)可能用若干空格或者換行符分隔開。輸入的第1個數(shù)為n,表示后續(xù)有n個數(shù)輸入。從輸入的第2個數(shù)開始,求出直到第n+1個數(shù)中最大的數(shù)和最小的數(shù)。Output 輸出為兩行,格式見sample。Sample Input 3 0 11Sample Output The maximum number is minimum number 分隔符是空格還是回車都是空白符,對scanf(”%d“)來說沒有區(qū)別;先讀入n,然后用for循環(huán)就很容易控制讀入n個數(shù)的過程。Append Code include int main(){int n,i,max,min。scanf(”%d“,amp。n)。int a[n]。for(i=0。iscanf(”%d“,amp。a[i])。max=a[0]。min=a[0]。for(i=0。i{if(maxmax=a[i]。if(mina[i])min=a[i]。}printf(”The maximum number is %“,max)。printf(”The minimum number is %d.“,min)。return 0。} D: 求100以內(nèi)的素數(shù) Description 素數(shù)是只能被1和自身整除的正整數(shù),根據(jù)數(shù)學定義1不是素數(shù)。素數(shù)也叫質(zhì)數(shù)。Input 輸入為兩個整數(shù)m和n,滿足0Output 從大到小輸出m~n之間的所有素數(shù),一個素數(shù)一行。如果m~n之間沒有素數(shù),則不輸出任何數(shù)。輸出的所有數(shù)在兩行“=====”之間。Sample Input 2 12Sample Output ===== 11 7 5 3 2 =====HINT 利用素數(shù)的數(shù)學規(guī)律可以很容易的解出此題,題目給出的數(shù)據(jù)范圍是關(guān)鍵。Append Code include include int main(){ int m,n,i,j,k,t。scanf(”%d %d“,amp。m,amp。n)。printf(”=====n“)。for(i=n。i=m。i){t=0。for(j=2。jif(i%j==0)t=1。if(t==0amp。amp。i1
點擊復制文檔內(nèi)容
環(huán)評公示相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖片鄂ICP備17016276號-1