zoukankan      html  css  js  c++  java
  • linux中VI编写C程序。。。

    在linux中编写C程序时不像编写shell那样开头要#!/bin/bash,但是在C程序中要指定头文件(头文件是指输入输出,宏等,而且要首先声明,也是必须要开始就声明的)

    写好C代码后要给C文件赋予可执行权限(chmod  755  xx.c)

    然后用gcc编译(方法和shell类似,shell是bash xx.sh   ,    而C是gcc xx.c ,C的程序文件名都是以 .c 结尾 , shell是都是以 .sh 结尾)

    以下上实例: 

    [root@localhost ~]# vim 1.c

    #include <stdio.h>
    int main()
    {
    float aa,bb,cc;
    printf("ENter aa temperature:");
    scanf("%f", &aa);
    printf("ENter bb temperature:");
    scanf("%f", &bb);
    cc = aa * bb;
    printf("cc is:%f ",cc );
    return 0;
    }

    [root@localhost ~]# chmod 755 1.c     //赋予C程序文件可执行权限

    [root@localhost ~]# gcc 1.c        //用gcc编译C程序文件,如果没有gcc请自行yum安装,编译完成之后会在“当前”目录下生成一个a.out的文件(权限是755)

    [root@localhost ~]# ./a.out         //执行/运行a.out文件

    ENter aa temperature:6.3
    ENter bb temperature:5.4
    cc is:34.020000            //aa * bb 的积是34.020000,因为用是float类型,所以这里会有小数点

  • 相关阅读:
    写代码的自动提示是怎么出来的...我的WebStorm中不能自动提示Bootstrap中的样式呢
    bootstrap 中是通过写less文件来生成css文件,用什么工具来编写呢?
    flexbox弹性盒模型
    oninput 属性
    操作文件
    深拷贝、浅拷贝、集合
    常用字符串方法
    字典-小练习
    字典
    元组
  • 原文地址:https://www.cnblogs.com/smlile-you-me/p/7123595.html
Copyright © 2011-2022 走看看