[解析]軟件設計中模塊划分應遵循的准則是高內聚低偶
合、模塊大小規模適當、模塊的依賴關系適當等。模塊的划
分應遵循一定的要求,以保證模塊划分合理,並進一步保證
以此為依據開發出的軟件系統可靠性強,易於理解和維護。
模塊之間的耦合應盡可能的低,模塊的內聚度應盡可能的
高。
#include <stdio.h> double fun(double e) { int i, k; double s, t, x; s=0; k=1; i=2; /**********found**********/ x=3.0/4; /**********found**********/ while(x > e) { s=s+k*x; k=k* (-1); t=2*i; /**********found**********/ x=(t+1)/(t*t); i++; } return s; } main() { double e=1e-3; printf("\nThe result is: %f\n",fun(e)); }
#include <stdio.h> /************found************/ double fun ( int n ) { int a, b, c, k; double s; s = 0.0; a = 2; b = 1; for ( k = 1; k <= n; k++ ) { /************found************/ s = s + (double)a / b; c = a; a = a + b; b = c; } return s; } main( ) { int n = 5; printf( "\nThe value of function is: %lf\n", fun ( n ) ); }
#include <stdio.h> #define M 4 int fun (int a[][M]) { int i,j,max=a[0][0]; for(i=0;i<2;i++) for(j=0;j<M;j++) if(max<a[i][j]) max=a[i][j]; return max; } main( ) { int arr[2][M]={5,8,3,45,76,-4,12,82} ;void NONO (); printf("max =%d\n", fun(arr)) ; NONO( ) ; } void NONO () {/* 本函數用於打開文件,輸入數據,調用函數,輸出數據,關閉文件。 */ FILE *wf ; int arr[][M]={5,8,3,90,76,-4,12,82} ; wf = fopen("out.dat","w") ; fprintf(wf, "max=%d\n", fun(arr)) ; fclose(wf) ; }