首页 > 代码库 > 头文件1

头文件1

 

头文件1

 

#include <stdio.h>double mean( double *y, int N ){    int    i;    double    s = 0.0;    for ( i = 0; i < N; i++ )        s = s + y[i];    s = s / (double) N;    return(s);}void main(){    double x[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };    printf( "mean = %lf\n", mean( x, 10 ) );}

----------------------------------------------

抽出部分 存入 a_x.h :

double mean( double *y, int N ){    int    i;    double    s = 0.0;    for ( i = 0; i < N; i++ )        s = s + y[i];    s = s / (double) N;    return(s);}

程序变:
#include <stdio.h>#include "a_x.h"void main(){    double x[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };    printf( "mean = %lf\n", mean( x, 10 ) );}

 

=============================================
你要是愿意随便抽一块也可以,例如抽出(也叫 a_x.h):
double mean( double *y, int N ){    int    i;    double    s = 0.0;    for ( i = 0; i < N; i++ )        s = s + y[i];    s = s / (double) N;    return(s);}void main(){

------------------------
程序变:
    #include<stdio.h>     #include "a_x.h"    double x[10]={1,2,3,4,5,6,7,8,9,10};    printf("mean = %lf\n", mean(x,10));}
==============================
语法上,功能上,两种抽法都可以。但第一种方法较好--程序可读性好,不易出错。

一般情况下,头文件里放 函数原型,全局量声明 和 函数定义。