在Mac上开发C语言程序,需要先安装xcode,之后使用gcc 命令编译
用文本编辑器新建一个C语言文件:
#include <stdio.h> int main() { int a,b,c,t; /*定义4个基本整型变量a,b,c,t*/ printf("Please input a,b,c:\n"); /*提示用户输入三个数字*/ scanf("%d%d%d",&a,&b,&c); /*接收用户输入3个数字,以空格分开*/ if(a > b) { t = a; a = b; b = t; } if(a > c){ t = a; a = c; c = t; } if(b > c){ t = b; b = c; c = t; } printf("The order of the number is:\n"); printf("%d,%d,%d\n",a,b,c); //打印排序结果 }
然后在终端命令窗口敲GCC命令:
gcc -o demo01.out demo01.c // gcc -0 是编译命令,demo01.out 可执行文件名称,demo01.c是源文件
./demo01.out //./是执行命令
运行结果:
Please input a,b,c:
22 11 23
The order of the number is:
11,22,23