`
qiufeihu
  • 浏览: 33281 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Mac下使用GCC开发C语言程序

C 
阅读更多

在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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics