糯米文學吧

位置:首頁 > 計算機 > C語言

計算機等考二級C語言學習要領

C語言2.4W

不少同學都覺得計算機語言很枯燥,對它毫無興趣,下面本站小編給大家分享計算機等考二級C語言學習要領,希望幫助到學習計算機感到迷茫的同學們。

計算機等考二級C語言學習要領

1、計算機語言挺枯燥的,如何提起興趣

答:首先要明確學習的目標,沒有明確的學習目標就沒有學習動力。給自己定一個目標,比如這次一定通過計算機等級考試,或者這個月學習完做個東西出來等等。其次,確定了目標之後,要認真去做,多上機操作實踐,遇到不懂的要多跟教師和其他學員交流,千萬不能放棄。當自己編的一段小程式執行通過,或攻下一道難題,自己就會獲得一種成就感,可能還會很興奮,也就漸漸有了興趣。最後,要把所學的知識運用到實際問題當中,這樣既可以鞏固所學的知識,不至於完學了就忘,還可以根據實際需要拓展知識面。這樣良性迴圈,興趣也會越來越濃。

2、有學員來信問到:我的電腦裡安裝的TURBO?C(970K)不能正常的'編譯,現象是:在編譯過程中,提示沒有錯誤也沒有警告,按任意鍵返回,可是在電腦上不能生成"OBJ"檔案,有時提示:Unable to open input file’’,我的朋友從他們學校的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("%fn",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("%fn",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:是這個檔案的路徑*/

/* install the graphic 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:%02dn",_hour,_min,_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(_sec*3.14f/30-3.14f/2)+x);

sins=(int)((r-10)*sin(_sec*3.14f/30-3.14f/2)+y);

cosm=(int)((r-19)*cos(_min*3.14f/30-3.14f/2)+x);

sinm=(int)((r-19)*sin(_min*3.14f/30-3.14f/2)+y);

cosh=(int)((r-28)*cos((_hour+(float)(_min)/60)*3.14f/6-3.14f/2)+x);

sinh=(int)((r-28)*sin((_hour+(float)(_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);

}

}

}