目录
(一)直接使用gcc编译C程序
1.编写C程序
- 编写main1.c
#include"sub1.h" int main() { int x=2,y=9; //定义x和y变量 printf("%.2f\n",x2x(x,y)); //输出处理后的值,保留两位小数 return 0; }
- 编写sub1.h
#ifndef __SUB1_H #define __SUB1_H #include<stdio.h> float x2x(int a,int b); //计算b除以a的结果 #endif
- 编写sub1.c
#include "sub1.h" /*******************/ /* 参数:a,b */ /* 返回值:ans */ /*******************/ float x2x(int a,int b) { float ans; ans=(float)b/a; return ans; }
2.gcc直接编译