本教程需要一定的黑客技术和Linux系统基础知识.
我们开始:)
首先新建立一个9x9.c的文件 然后用gedit打开文件,这时候输入程序代码 他会自动识别函数 并用不同的颜色标记.
代码如下(很简单的循环嵌套)
#include <stdio.h>
#include <iostream.h>
main()
{
int iLie;
int iPri;
int iResl;
printf("A Program Print 9X9 form..Code By BestWC...For My 19th Brithday!\n\n");
for (iLie=1;iLie<=9;iLie++)
{
for (iPri=1;iPri<=iLie;iPri++)
{
iResl=iLie*iPri;
printf("%dx%d=%d ",iPri,iLie,iResl);
};
//printf("\n");
cout<<endl;
};
printf("\n练习了FOR循环的嵌套...Happy Birthday To Me...Enjoy it``` ^_^\n");
}
保存好后我们开始编译:
[root@NewStar8 dns]# cd /Pro-Lea //进入代码文件的目录
[root@NewStar8 Pro-Lea]# ls //看看当前目录有哪些文件
9x9 AddSum.c dns first Pro-Lea.tar.gz
9x9.c b2d dnsxpl.Idl PowerFunc
AddSum b2d.c dnsxpl.v2.1.zip PowerFunc.c //看到9x9.c了吧
[root@NewStar8 Pro-Lea]# gcc -o 9x9 9x9.c //我们用gcc编译
-o表示输出 这个命令是告诉gcc 把9x9.c的代码编译成9x9的可执行文件(Linux系统不需要扩展名标记)
9x9.c:2:22: iostream.h: 没有那个文件或目录
9x9.c: In function `main':
9x9.c:21: error: `cout' undeclared (first use in this function)
9x9.c:21: error: (Each undeclared identifier is reported only once
9x9.c:21: error: for each function it appears in.)
9x9.c:21: error: `endl' undeclared (first use in this function)
//报错了,看看提示:iostream.h: 没有那个文件或目录 这个是因为我用了c++中的cou 和 cin 函数,而这两个函数在iostream.h标准输入输出流头文件中定义 但gcc找不到
因为gcc普遍用来编译c语言程序 而cou cin在c++出现后才被定义,那么我们换个编译方式.
[root@NewStar8 Pro-Lea]# c++ -o 9x9 9x9.c //用c++命令来编译
In file included from /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/backward/iostream.h:31,
from 9x9.c:2:
/usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.//貌似成功了
[root@NewStar8 Pro-Lea]# ./9x9 //./代表当前目录 9x9是可执行文件的名子
A Program Print 9X9 form..Code By BestWC...For My 19th Brithday!
1x1=1
1x2=2 2x2=4
1x3=3 2x3=6 3x3=9
1x4=4 2x4=8 3x4=12 4x4=16
1x5=5 2x5=10 3x5=15 4x5=20 5x5=25
1x6=6 2x6=12 3x6=18 4x6=24 5x6=30 6x6=36
1x7=7 2x7=14 3x7=21 4x7=28 5x7=35 6x7=42 7x7=49
1x8=8 2x8=16 3x8=24 4x8=32 5x8=40 6x8=48 7x8=56 8x8=64
1x9=9 2x9=18 3x9=27 4x9=36 5x9=45 6x9=54 7x9=63 8x9=72 9x9=81
练习了FOR循环的嵌套...Happy Birthday To Me...Enjoy it``` ^_^
[root@NewStar8 Pro-Lea]# //呵呵 运行成功了.
先到这里吧:) 以后我会陆续写一些相关的linux教程 希望对大家有所帮助:) |