Ubuntu的系统下C语言的简单程序
编写一个主程序文件main1.c和sub.c对两个参数进行运算
main1.c主程序:
include<stdio.h>
int main()
{
int a,b;
float c;
a=15;b=25;
c=x2x(a,b);
printf("%f",c);
return 0;
}
sub1.c主程序
include<stdio.h>
float x2x(int a,int b)
{
float c;
c=(a+b)*a*b;
return c;
}
用gcc对main1.c和sub1.c函数进行编译
gcc main1.c sub1.c
输出
gcc用于编译后会生成可执行文件file.out文件,可用./file.out来执行可执行文件
Windows下运用vc6进行编译
main1.c的代码
#include<stdio.h>
float x2x(int a,int b)
{
float c;
c=(a+b)*a*b;
return c;
}
int main()
{
int a,b;
float c;
a=15;b=25;
c=x2x(a,b);
printf("%f",c);
return 0;
}
输出
用makefile的方式编程主程序
sub1.h
float x2x(int a,int b);
makefile文件
main1:main1.o sub1.o
gcc -o main1 main1.o sub1.o
main1.c:main1.c sub1.h
gcc -c main1.c
sub1.o:sub1.c sub1.h
gcc -c sub1.c
clean:
rp *.o main1
用make命令执行
输出