【正文】
若每步跨2階,最后剩下1階;若每步跨3階,最后剩下2階;若每步跨5階,最后剩下4階;若每步跨6階,則最后剩下5階;只有每步跨7階,最后才正好1階不剩。include main(){ int x = 1, find = 0。 { if (x%2=1 amp。 x%3=2 amp。 x%5=4 amp。 x%6=5 amp。 x%7=0) { printf(x = %d\n, x)。 x++。 while (!find) { if (x % 2 == 1 amp。 x % 3 == 2 amp。 x % 5 == 4 amp。 x % 6 == 5 amp。 x % 7 == 0) { printf(x = %d\n, x)。 } x++。要求輸入變量定義為int類型且由用戶從鍵盤輸入。 printf(Input an integer number:\n)。n)。 if (m) printf(%d is an odd number\n, n)。}2728.用動態(tài)數(shù)組編程輸入任意m個班學(xué)生(每班n個學(xué)生)的某門課的成績,計算最高分,并指出具有該最高分成績的學(xué)生是第幾個班的第幾個學(xué)生。輸入提示信息:Input array size m,n:Input %d*%d array:\n輸入格式:%d,%d輸出提示信息和格式:maxScore = %d, class = %d, number = %d\n答案:include include void InputScore(int *p, int m, int n)。int main(){ int *pScore, m, n, maxScore, row, col。 scanf(%d,%d, amp。n)。 /* 申請動態(tài)內(nèi)存 */ if (pScore == NULL) { printf(No enough memory!\n)。 } InputScore(pScore, m, n)。row, amp。 printf(maxScore = %d, class = %d, number = %d\n, maxScore, row + 1, col + 1)。 /* 釋放動態(tài)內(nèi)存 */ return 0。 printf(Input %d*%d array:\n, m, n)。 i m。 j n。p[i * n + j])。 *pRow = 0。 for (i = 0。 i++) { for (j = 0。 j++) { if (p[i * n + j] max) { max = p[i * n + j]。 /*記錄行下標(biāo)*/ *pCol = j。}2829.下面程序的功能是交換變量a和b中的值。include main(){ int a,b,*p,*q,*t。a。b。 scanf(%d%d, amp。q)。 *p=*q 。 printf(交換后a和b的值:a=%d b=%d\n,a,b)。 a,b,*p,*q,*t。a。b。 printf(請輸入變量a和b的值:)。a,amp。 *t=*p 。*q=*t 。}2930.編程打印200~300之間所有素數(shù)。判斷一個數(shù)是否是素數(shù)函數(shù)原型為: int fun(int m)。main(){ int a。a = 300。 else continue。 for (i = 2。i++) { if(m%i == 0) return 0。 } return 1。要求按如下原型編寫統(tǒng)計成績在全班平均分及平均分之上的學(xué)生人數(shù)int GetAboveAver(int score[], int n)。int GetAboveAver(int score[], int n)。 i = 40。 scanf(%d, amp。 if (b = 0) a[i] = b。 } printf(Total students are %d\n, i)。}int GetAboveAver(int score[], int n){ int sum = 0, c。 for (c = 0。 c++) { sum = sum + score[c]。 printf(Average score is %d\n, d)。c i。 else continue。 return 0。要求使其能進行浮點數(shù)的算術(shù)運算,同時允許使用字符*、x與X作為乘號,并且允許輸入的算術(shù)表達式中的操作數(shù)和運算符之間可以加入任意多個空格符。 char c。 scanf(%f %c %f,amp。c, amp。 if (c == 39。) printf(%f + %f = %f \n, a, b, a + b)。39。 else if (c == 39。) { if (b != 0) printf(%f / %f = %f \n, a, b, a / b)。 } else if (c == 39。 || c == 39。 || c == 39。) printf(%f * %f = %f \n, a, b, a*b)。^39。 else printf(Invalid operator! \n)。include int MinCommonMultiple(int a, int b)printf(Input a,b:)。 x=MinCommonMultiple(int a,int b)。}int MinCommonMultiple(int a, int b)。for (i=1。 i++){if (i%a==0 || i%b==0)return i。int main(){ int a, b, x。 scanf(%d,%d, amp。b)。 printf(MinCommonMultiple = %d\n, x)。 for (i = 1。 i++) { if (i%a == 0 amp。 i%b == 0) return i。m , n 是兩個正整數(shù),且 mn. P= m!/(n!*(mn)!)**輸入格式要求:%d %d 提示信息:請輸入m,n的值( mn ):\n**輸出格式要求:n項之和為:%lf\n程序運行示例如下:請輸入m,n的值( mn ):5 3n項之和為:答案:include int fuc(int m, int n)。int main(){int m, n。scanf(%d %d,amp。n)。}int fuc(int m, int n){int p。return p。}int sum_s(int i){int s_ = 1, a。a =i。}return s_。用函數(shù)編程實現(xiàn)計算兩個正整數(shù)的最小公倍數(shù)(Least Common Multiple,LCM)的函數(shù),在主函數(shù)中調(diào)用該函數(shù)計算并輸出從鍵盤任意輸入的兩整數(shù)的最小公倍數(shù)。int main(){int a, b。scanf(%d,%d,amp。b)。printf(Least Common Multiple of %d and %d is %d\n, a, b, Lcm(a, b))。printf(Input error!\n)。if (a 0 amp。 b 0)for (i = 1。i++){if ((i % a == 0) amp。 (i % b == 0))}}3435.輸入某班學(xué)生某門課的成績(最多不超過40人),當(dāng)輸入為負(fù)值時,表示輸入結(jié)束,用函數(shù)編程統(tǒng)計成績不低于平均分的學(xué)生人數(shù)。(2)在主函數(shù)中: 輸入學(xué)生成績, 然后調(diào)用函數(shù)GetAboveAver計算成績不低于平均分的學(xué)生人數(shù), 最后輸出該人數(shù)。int GetAboveAver(int score[], int n)。 i = 40。scanf(%d, amp。if (b = 0)a[i] = b。}GetAboveAver(a, i)。int d, e = 0。c i。}for (c = 0。 c++){if (score[c] = d)e++。}printf(Students of above average is %d\n, e)。}3536.從鍵盤任意輸入10個整數(shù)存入一個數(shù)組中,然后任意輸入一個整數(shù)x,采用順序查找法,在數(shù)組中查找該數(shù),如果找到,則函數(shù)返回該數(shù)在數(shù)組中的下標(biāo)位置,并在主函數(shù)中打印該值;如果沒有找到,則返回1,并在主函數(shù)中打印“Not found!”。int Search(int a[], int n, int x)。要求必須按照題目要求和用函數(shù)編程,否則不給分。int b[10] = {0}。printf(Input 10 numbers:\n)。 x 10。{n)。b[x] = n。}printf(Input x:\n)。x)。if (Search(b,n,x) 0)else}int Search(int a[], int n, int x ){for (n = 0。 n++){if (a[n] == x)else}return 1。要求如下:(1)在子函數(shù)Inverse中實現(xiàn)字符串的逆序存放。(2)在主函數(shù)中 從鍵盤輸入字符串(使用gets函數(shù)) 然后,調(diào)用Inverse函數(shù), 最后,輸出逆序后的字符串。答案:includechar str_1[81]。int main(){ printf(Input a string:\n)。 Inverse(str_1)。 int a, c。a 81。\039。 else continue。c (a) / 。 str[c] = str[(a 1) c]。 } printf(Inversed results:\n)。}3738.從鍵盤任意輸入一個字符串,計算其實際字符個數(shù)并打印輸出,即不使用字符串處理函數(shù)strlen()編程實現(xiàn)strlen()的功能。char str[100]。gets(str)。a 100。\039。break。}printf(The length of the string is: %u\n,a)。請找出以下程序的錯誤,并改正之。 main() { char str[ARR_SIZE]。 int letter=0,digit=0,space=0,other=0。 gets(str)。 for (i=0。 i++) { if (a=str[i]=z || A=str[