例題:撰寫函式fun,它的功能是:求m以內(不包括m)同時能被3與7整除的所有自然數之和的平方根a,并作為函式值回傳,
例如,若m為500時,函式值a=76.131465,
請勿改動主函式main與其它函式中的任何內容,僅在函式fun的花括號中填入所撰寫的若干陳述句,
代碼如下:
#include<conio.h>
#include<math.h>
#include<stdio.h>
double fun(int m)
{
double a=0.0;
int i;
for(i=1;i<m;i++)
if(i%3==0&&i%7==0)
a=a+i;
a=sqrt(a);
return a;
}
main()
{
FILE*out;
printf("s=%f\n",fun(500));
out=fopen("outfile.dat","w");
fprintf(out,"%f",fun(200));
fclose(out);
}
輸出運行視窗如下:

越努力越幸運!
加油,奧力給!!!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/243580.html
標籤:其他
上一篇:再見 2020 !—— 年度總結
