zoukankan      html  css  js  c++  java
  • 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(""请输入五个数字: ");
    scanf("%d %d %d %d %d",&x1,&x2,&x3,&x4,&x5);
    av=avg(x1,x2,x3,x4,x5);
    printf("平均值是:%f ",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("请输入五个数字: ");
    scanf("%d %d %d %d %d",&x1,&x2,&x3,&x4,&x5);
    mi=min(x1,x2,x3,x4,x5);
    printf("最小值是:%d ",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
  • 相关阅读:
    beautifulsoup部分知识点
    navicat 结合快捷键
    byte[i] & 0xFF原因(byte为什么要与上0xff?)
    Java parseInt()和parseFloat()的用法
    parse 方法
    getTime()和parse()的区别
    使用SQL Profiler trace(2005)的经验分享(新建跟踪、分析跟踪文件)
    DWZ使用笔记
    js中 json详解
    src与href属性的区别
  • 原文地址:https://www.cnblogs.com/zhangaihua/p/3718121.html
Copyright © 2011-2022 走看看