C補強階段作業(yè)_第1頁
C補強階段作業(yè)_第2頁
C補強階段作業(yè)_第3頁
C補強階段作業(yè)_第4頁
C補強階段作業(yè)_第5頁
已閱讀5頁,還剩10頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、寫函數(shù)。 函數(shù)的三個參數(shù)是一個字符和兩個整數(shù)。 字符參數(shù)是要輸出的字符。 第一個整數(shù)表示要輸出到每行的字符數(shù),第二個整數(shù)表示要輸出的行數(shù)。 創(chuàng)建一個調(diào)用函數(shù)的程序。 請求:如果輸入字符為回車,則在輸入要作為未輸入字符處理的矩陣值時,如果不是數(shù)字,則直接結(jié)束程序。編程考試點:循環(huán)基本語法break和continue#includevoid chLineRow(char ch、int c、int r )int main(void) char ch;int col、row;打印( enteraracharacter (# to quit ) : );while (ch=getchar () )! 輸

2、入=#。 2if (ch=n )繼續(xù);printf ( enternumberofcolumnsandnumberofrows : );PS ( % d % d ,col,row )!=2)break;chLineRow(ch、col、row )printf (componenternextcharacter (# to quit ) : );以下打印( bye! n );返回0;以下void chLineRow(char ch,int c,int r) int col、row;for (row=0; row r; 表示row )for (col=0; col c; col )putchar(

3、ch )putchar(n )以下返回;以下編寫計算雙精度型數(shù)的整數(shù)次方的函數(shù)(不能調(diào)用系統(tǒng)的函數(shù)pow )。 請注意0的任意乘方和任意數(shù)值的0乘方和負乘方制定測試程序。編程試驗點: if-else的嵌套#include雙電源(雙電源a,int b) /* ANSI prototype */PS (PS ) PS雙倍x,xpow;PS;printf ( enteranumberandtheintegerpower );printf ( toe whichnthenumberwillberaised.enterq );打印( to quit. n );while (“% lf % d”,x,n)

4、=2) )xpow=電源(x,n )/*功能呼叫* /打印( %.3 gtothepower % diss %.5gn ,x,n,xpow );printf ( enternextpairofnumbersorqtoquit. n );以下打印( hopeyouenjoythispowertrip- bye! n );返回0;以下雙電源(雙電源a,int b )/*功能定義* /舉止雙面pow=1;PS;表示if (b=0) /if (a=0)/printf(0 to the 0 undefined; using 1 as the valuen ;pow=1.0; else if (a=0)p

5、ow=0.0;else if (b 0)for (i=1; i=b; PS )pow *=a;else/* b 0 */pow=1.0 /電源(a,-b )返回點; /*返回值* /以下編寫計算降水量的程序,給出排列,記錄每年的每月降水量constfloatrain yrs months =1122222222222652 10.2、8.1、6.8、4.2、2.1、1.8、0.2、0.3、1.1、2.3、6.1、7.4 , 9.2、9.8、4.4、3.3、2.2、0.8、0.4、0.0、0.6、1.7、4.3、5.2 ,6. 6、5.5、3.8、2.8、1.6、0.2、0.0、0.0、1.3、

6、2.6、4.2 , 4.3、4.3、4.3、3.0、2.0、1.0、0.2、0.2、0.4、2.4、3.5、6.6 , 8.5,8.2,1.2,1.6,2.4,0.0,5.2,0.9,0.3,0.9,1.4,7.2 使用指針而不是下標來計算,年降水量的合計值、年平均值、每月平均量編程點:用指針配置二維數(shù)組元素的方法#include# define months 12/* numberofmonthsinayear * /# define yrs5/* numberofyearsofdata * /int main(void) /* initializingrainfalltdatafor 19

7、90-1994 * /constfloatrain 5 12 = 10.2,8.1,6.8,4.2,2.1,1.8,0.20.3、1.1、2.3、6.1、7.4、9.2、9.8、4.4、3.3、2.2、0.8、0.40.0,0.6,1.7,4.3,5.2,6.6,5.5,3.8,2.8,1.6,0.2,0.00.0,0.0,1.3,2.6,4.2,4.3,4.3,3.0,2.0,1.0,0.20.2、0.4、2.4、3.5、6.6、8.5、8.2、1.2、1.6、2.4、0.0、5.20.9、0.3、0.9、1.4、7.2英年,蒙特h;浮動輔塔,總;打印( yea rainfall (inch

8、es )n );for (年=0,總數(shù)=0; year YRS; year ) /* for each year,sumrainfallforeforeachmonth*/for (month=0,輔tot=0; monthmonthmonths; month )輔tot=* (* (rain year ) month;打印(.1fn ,1990年,輔托;總數(shù)=輔tot;/*所有年度總額* /以下打印(nthyearlyaverageis %.1 finches. nn ,總/yrs;printf ( monhlyaverages :nn );printf ( janfebmaraprmayj

9、unjulaugsepoct );打印( nov decn );for (month=0; monthmonthmonths; month ) /* for each month,sumrainfalloffyears*/for (年=0,輔頭=0; year YRS; 年)輔tot=* (* (rain year ) month;printf(%4.1f ,輔tot/yrs );以下printf(n );返回0;以下創(chuàng)建一個程序,要求用戶輸入三個數(shù)據(jù)集。 每個數(shù)據(jù)集都包含五個雙精度值。 程序必須實現(xiàn)以下所有功能:的:a .將輸入信息存儲在3*5的陣列中b .計算每個數(shù)組(包括五個值)的平均值

10、c .計算所有數(shù)值的平均值d .找到這15個中的最大值打印結(jié)果每個任務(wù)都需要用單獨的函數(shù)實現(xiàn)。 任務(wù)b需要描述計算和返回一維數(shù)組平均值的函數(shù),并重復(fù)調(diào)用三次該函數(shù)來實現(xiàn)任務(wù)b。 對于任務(wù)c、d,函數(shù)必須以整個數(shù)組為參數(shù),完成任務(wù)b、c、d的函數(shù)必須向調(diào)用函數(shù)返回答案(推薦可變長度數(shù)組,參照程序用可變長度數(shù)組實現(xiàn))編程試驗點:循環(huán)和二維序列的熟練應(yīng)用,將序列作為參數(shù)傳遞#include#define ROWS 3#define COLS 5void store (雙倍ar ,int n )雙平衡二維(int cols,int cols,double arrowscols );雙矩陣(int co

11、ls,int cols,雙矩陣 rows cols );void showarr2(int rows,int cols,double arrowscols );雙值(const double ar ,int n );PS (PS ) PS雙精靈 rows cols ;int row;for (row=0; 行行; 表示row )打印機( enter % dnumbersforrow % dn 、COLS、row 1);store(stuffrow,COLS )以下打印(陣列內(nèi)容:n );showarr2(ROWS、COLS、stuff )for (row=0; row ROWS; row )打

12、印( averagevalueofrow % d=% gn ,row 1,average(stuffrow )COLS );打印( averagevalueofallrows=% gn ,average2d(ROWS,COLS,stuff ) );printf(largestvalue=%gn ,max2d(ROWS,COLS,stuff ) );打印( bye! n );返回0;以下void store (雙倍ar ,int n) )PS;for (i=0; PS; 表示I )打印機( enter value # 360 ,i 1 );掃描( % lf ,ari );以下以下雙值2 d (i

13、nt rows,int cols,雙值ar rows cols )int r、c;雙求和=0.0;for (r=0; r rows; r )for (c=0; c cols; c )sum=ar r ;if (rows * cols 0)返回和/(rows * cols )else返回0.0;以下雙行軸(int cols,int cols,雙行軸 rows cols )int r、c;雙最大值=ar 0 0;for (r=0; r rows; r )for (c=0; c cols; c )if (max arrc )max=ar r ;返回最大值;以下void showarr2(int rows,int cols,double arrowscols) )int row、col;for (row=0; 行行; 表示row )for (col=0; col cols; col )打印( % g ,arrowcol );putc

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論