Chinaunix首页 | 论坛 | 博客
  • 博客访问: 92453561
  • 博文数量: 19283
  • 博客积分: 9968
  • 博客等级: 上将
  • 技术积分: 196062
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-07 14:28
文章分类

全部博文(19283)

文章存档

2011年(1)

2009年(125)

2008年(19094)

2007年(63)

分类: C/C++

2008-04-20 16:04:00

来自:

1、计算机语言挺枯燥的,如何提起兴趣
答:首先要明确学习的目标,没有明确的学习目标就没有学习动力。给自己定一个目标,比如这次一定通过计算机等级考试,或者这个月学习完做个东西出来等等。其次,确定了目标之后,要认真去做,多上机操作实践,遇到不懂的要多跟教师和其他学员交流,千万不能放弃。当自己编的一段小程序运行通过,或攻下一道难题,自己就会获得一种成就感,可能还会很兴奋,也就渐渐有了兴趣。最后,要把所学的知识运用到实际问题当中,这样既可以巩固所学的知识,不至于完学了就忘,还可以根据实际需要拓展知识面。这样良性循环,兴趣也会越来越浓。

2、有学员来信问到:我的电脑里安装的TURBO?C(970K)不能正常的编译,现象是:在编译过程中,提示没有错误也没有警告,按任意键返回,可是在电脑上不能生成"OBJ"文件,有时提示:Unable to open input file’cos.obj’,我的朋友从他们学校的PC上拷贝回来的程序也出现这个问题?!在他们学校却很正常,这是怎么回事?这个问题一直在困扰我,使我的学习不能进行下去!请帮我解决。谢谢!
答:这需要重新设置options--directories中的include目录和lib目录,设为你C的安装目录就可以了。记住要保存哟!
3、#include
main()
{int m=7,n=4;
float a=38.4,b=6.4,x;
x=m/2+n*a/b+1/2;
printf("%f\n",x);
}
这个程序的结果是27.000000
为什么我一直算的是28.000000呢?请指教
答:main()
{
int m=7,n=4;
float a=38.4,b=6.4,x;
x=m/2+n*a/b+1/2;
printf("%f\n",x);
}
m/2==3;因为m是整形所以结果为整形不是3.5而是3
同样1/2不是0.5而是0。
要改的话,x=(float)m/2+n*a/b+1.0/2.0;
结果为28.0000

4、有些人说我的程序很难让人看懂,请问如何将程序写得规范、简洁明了
答:这是编程中重要的一点,要养成良好的编程习惯。请看一个例题:程序很简单,是用TURBO C编一个时钟程序。具体如下:
/****************************************************
Module:clock.c
just a test of my programming ability
*****************************************************/
#include"math.h"
#include"dos.h"
#include"stdio.h"
#include"graphics.h"
main()
{
char s[30];
int gdriver,gmode;
int cosh,sinh,cosm,sinm,coss,sins;
struct ;time t;
char keydown=0;
int x=300,y=160,r=40;
clrscr();
gdriver=9; gmode=1;
initgraph(&gdriver,&gmode,"a:\\");/*需要说明的是,第三个参数a:\\是egavga.bgi这个文件的路径*/

/* install the graphic device.the third parameter is the path of the driver*/

setbkcolor(0);
setcolor(WHITE);
while(1)
{

circle(x,y,r);/*paintthecircle*/

line(x,y+r-10,x,y+r-12);
line(x+r-4,y,x+r,y);
line(x-r,y,x-r+4,y);
line(x,y-r+10,x,y-r+10+2); /* draw the fout scales */

gettime(&t);
sprintf(s,"The current time is %2d:%02d:%02d\n",t.ti_hour,t.ti_min,t.ti_sec,t);
outtextxy(0,0,s); /* out put the current time */
outtextxy(0,10,"This clock is written by lijun"); /*?show the auther */
coss=(int)((r-10)*cos(t.ti_sec*3.14f/30-3.14f/2)+x);
sins=(int)((r-10)*sin(t.ti_sec*3.14f/30-3.14f/2)+y);
cosm=(int)((r-19)*cos(t.ti_min*3.14f/30-3.14f/2)+x);
sinm=(int)((r-19)*sin(t.ti_min*3.14f/30-3.14f/2)+y);
cosh=(int)((r-28)*cos((t.ti_hour+(float)(t.ti_min)/60)*3.14f/6-3.14f/2)+x);
sinh=(int)((r-28)*sin((t.ti_hour+(float)(t.ti_min)/60)*3.14f/6-3.14f/2)+y);

/* calculate the position of the three points */
setcolor(14);
line(x,y,coss,sins);
setcolor(13);
line(x,y,cosm,sinm);
setcolor(10);
line(x,y,cosh,sinh);
setcolor(15);

/* draw the points */

sleep(1);
clrscr();&nb

sp;
keydown=kbhit();/* check whether key down */
if(keydown)
{
closegraph();/* close graphic device */
exit(0);
}
}

}

阅读(176) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~