摘要: 编译简单的C程序 C语言经典的入门例子是HelloWorld,下面是一示例代码: #includeintmain(void){ printf("Hello,world!\n");return0;} 我们假定该代码存为文件‘hello.c’。要用gcc编译该文件,使用下面的命令: $gcc-g-Wallhello.c-ohello 该命令将文件‘hello.c’中的代码编译为机器码并存储在可执行文件‘hello’中。机器码的文件名是通过-o选项指定的。该选项通常作为命令行中的最后一个参数。如果被省略,输出文件默认为‘a.out’。 注意到如果当前目录中与可执行文件重名的文件已 阅读全文
posted @ 2013-07-13 14:48 emanlee 阅读(4243) 评论(0) 推荐(0)
摘要: #include #include void randomlize(int *a, int n){ int i = 0,j = 0, k = 0; for(i = 0; i < n; i++) { j = rand()%(n-i)+i; k = a[i]; a[i] = a[j]; a[j] = k; } }int main(void){ int i; int a[]={1,2,3,4,5,6,7,8,9}; randomlize(a,9); for(i = 0; i < 9; i++) { printf("%d ",a[i]); } return ... 阅读全文
posted @ 2013-07-13 08:52 emanlee 阅读(2431) 评论(0) 推荐(0)
摘要: #include#include #include "time.h" int main( void ) { long i = 1000000000L; clock_t start_time, end_time; double duration_time; start_time=clock(); while( i-- ) ; end_time = clock(); duration_time = (double)(end_time-start_time) / CLOCKS_PER_SEC; printf( "duration: %lf seconds\n" 阅读全文
posted @ 2013-07-13 08:26 emanlee 阅读(2223) 评论(0) 推荐(0)