1.编写一个简单的C语言程序:计算输入多个整数的平均值,并将此程序分割成多个小文件。 2.为第1题中的程序编写makefile文件,用make编译后改成返回最小值,再编译,观察有多少文件不需要重新

1.编写一个简单的C语言程序:计算输入多个整数的平均值,并将此程序分割成多个小文件。
 2.为第1题中的程序编写makefile文件,用make编译后改成返回最小值,再编译,观察有多少文件不需要重新编译。
1.avg.h
float avg(int x1,int x2,int x3,int x4,int x5);
avg.c
float avg(int x1,int x2,int x3,int x4,int x5)
{
return (float)(x1+x2+x3+x4+x5)/5;
}
main.c
#include<stdio.h>
#include"avg.h"
int main()
{
int x1,x2,x3,x4,x5;
float av;
printf(""请输入五个数字:\n");
scanf("%d %d %d %d %d",&x1,&x2,&x3,&x4,&x5);
av=avg(x1,x2,x3,x4,x5);
printf("平均值是:%f\n",avg);
return 0;
}
[root@localhost test]# gcc avg.c main.c -o test
[root@localhost test]# ./test
清输入五个数字:
12 32 6 5 8
平均值是:12.600000
2.main.c
#include<stdio.h>
#include"min.h"
int min(int x1,int x2,int x3,int x4,int x5);
int main()
{
int x1,x2,x3,x4,x5;
int mi;
printf("请输入五个数字:\n");
scanf("%d %d %d %d %d",&x1,&x2,&x3,&x4,&x5);
mi=min(x1,x2,x3,x4,x5);
printf("最小值是:%d\n",mi);
return 0;
}
min.c
int min(int x1,int x2,int x3,int x4,int x5)
{
int min=x1,x[5]={x1,x2,x3,x4,x5};


for(int i=0;i<5;i++)
{
if(x[i]<min)
min=x[i];


}
return x[i];
}
min.h
int min(int x1,int x2,int x3,int x4,int x5);
2.makefile
d:main.o min.o min.h
gcc main.o min.o -o d
main.o:main.c
gcc main.c -c
min.o:min.c
gcc min.c -c
[root@localhost test1]# make
gcc main.c -c
gcc min.c -c
请输入五个数字:
12 6 3 5 6
最小值是:3
posted @ 2013-10-12 08:25  ZhangAihua  阅读(1447)  评论(0编辑  收藏  举报