C語言游戲源代碼_第1頁
C語言游戲源代碼_第2頁
C語言游戲源代碼_第3頁
C語言游戲源代碼_第4頁
C語言游戲源代碼_第5頁
已閱讀5頁,還剩79頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、c 語言游戲源代碼1、 簡單的開機密碼程序#include #include #include void error()window(12,10,68,10);textbackground(15);textcolor(132);clrscr();cprintf(file or system error! you cant enter the system!); while(1); /*若有錯誤不能通過程序*/void look()file *fauto,*fbak;char *pass=c:windows; /*本程序的位置*/char a25,ch;char *au=,*bname=hecf

2、back.; /*bname 是 的備份*/setdisk(2); /*set currently disk c:*/chdir(); /*set currently directory */fauto=fopen(au,r+);if (fauto=null)fauto=fopen(au,w+);if (fauto=null) error();fread(a,23,1,fauto); /*讀取前 23 各字符*/a23=0;if (strcmp(a,pass)=0) /*若讀取的和 pass 指針一樣就關(guān)閉文件,不然就添加 */fclose(fauto);elsefbak=fopen(bnam

3、e,w+);if (fbak=null) error();fwrite(pass,23,1,fbak);fputc(n,fbak);rewind(fauto);while(!feof(fauto)ch=fgetc(fauto);fputc(ch,fbak);rewind(fauto);rewind(fbak);while(!feof(fbak)ch=fgetc(fbak);fputc(ch,fauto);fclose(fauto);fclose(fbak);remove(bname); /*del bname file*/void pass()char input60;int n;while(

4、1)window(1,1,80,25);textbackground(0);textcolor(15);clrscr();n=0;window(20,12,60,12);textbackground(1);textcolor(15);clrscr();cprintf(password:);while(1)inputn=getch();if (n58) putchar(7); break; /*若字符多于 58 個字符就結(jié)束本次輸入*/ if (inputn=13) break;if (inputn=32 & inputn0)cprintf(b b);inputn=0;n-;inputn=0;i

5、f (strcmp(password,input)=0)break;elseputchar(7);window(30,14,50,14);textbackground(15);textcolor(132);clrscr();cprintf(password error!);getch();main()look();pass();2、 彩色貪吃蛇#include #include #define n 200#define up 0x4800#define down 0x5000#define left 0x4b00#define right 0x4d00#define esc 0x011b#de

6、fine y 0x1579#define n 0x316eint gamespeed; /* 游戲速度 */int i, key, color;int score = 0; /* 游戲分數(shù) */char cai48h =0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x

7、04, 0x00, 0x18, 0x00, 0x00, 0x00, 0x0e, 0x00,0x1c, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x1c, 0x00,0x00, 0x00, 0x20, 0x00, 0x38, 0x00, 0x00, 0x00,0x40, 0x00, 0x78, 0x00, 0x00, 0x01, 0x80, 0x40,0x70, 0x00, 0x00, 0x03, 0x80, 0xc0, 0xe0, 0x00,0x00, 0x07, 0x80, 0x80, 0xc0, 0x00, 0x00, 0x0e,0x11, 0x81, 0xc0, 0x

8、00, 0x00, 0x08, 0x61, 0x01,0x80, 0x00, 0x00, 0x00, 0x23, 0x03, 0x04, 0x00,0x00, 0x02, 0x02, 0x00, 0x06, 0x00, 0x00, 0x1e,0x04, 0x00, 0x0f, 0x00, 0x00, 0x1c, 0x1f, 0x80,0x1e, 0x00, 0x00, 0x08, 0x3f, 0x80, 0x3c, 0x00,0x00, 0x00, 0xff, 0x80, 0x38, 0x00, 0x00, 0x03,0xff, 0x80, 0x78, 0x00, 0x00, 0x0f, 0x

9、f8, 0x00,0xf0, 0x00, 0x00, 0x7f, 0xf0, 0x00, 0xe0, 0x00,0x03, 0xff, 0xfc, 0x01, 0x80, 0x00, 0x03, 0xc0,0xff, 0x01, 0x03, 0x80, 0x01, 0x01, 0xff, 0x00,0x03, 0x80, 0x00, 0x01, 0x3f, 0x00, 0x07, 0x80,0x00, 0x02, 0x11, 0x00, 0x07, 0x00, 0x00, 0x00,0x10, 0x00, 0x07, 0x00, 0x00, 0x00, 0x10, 0x00,0x0e, 0x0

10、0, 0x00, 0x08, 0x10, 0x00, 0x1c, 0x00,0x00, 0x30, 0x10, 0x00, 0x18, 0x00, 0x00, 0x70,0x10, 0x00, 0x30, 0x00, 0x01, 0xe0, 0x10, 0x00,0x70, 0x00, 0x03, 0x80, 0x10, 0x00, 0x60, 0x00,0x00, 0x00, 0x30, 0x00, 0xe0, 0x00, 0x00, 0x00,0xf0, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x70, 0x03,0xc0, 0x00, 0x00, 0x00, 0x1

11、0, 0x07, 0x80, 0x00,0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00,0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c,0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00,0x00, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0

12、0,;char she48h =0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00,0x

13、00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00,0x00, 0x0e, 0x00, 0x00, 0x00, 0x03, 0x00, 0x07,0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00,0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,0x00, 0x00, 0xf8, 0x00, 0x00, 0x02, 0x00, 0x07,0x86, 0x00, 0x00, 0x02, 0x00, 0x18, 0x03, 0x00,0x00, 0x02, 0x00, 0x

14、00, 0x07, 0x80, 0x00, 0x03,0xf0, 0x00, 0x07, 0x80, 0x00, 0x0f, 0xfc, 0x00,0x0c, 0x00, 0x00, 0x7e, 0x3f, 0x80, 0x00, 0x00,0x01, 0xfe, 0x1f, 0x80, 0x00, 0x00, 0x01, 0xe2,0x39, 0x8c, 0x00, 0x00, 0x00, 0xc2, 0x30, 0x08,0x00, 0x00, 0x00, 0xc2, 0x60, 0x08, 0x00, 0x00,0x00, 0xc3, 0xe0, 0x08, 0x60, 0x00, 0x

15、00, 0x7f,0xe0, 0x01, 0xe0, 0x00, 0x00, 0x3f, 0x80, 0x1f,0xe0, 0x00, 0x00, 0x1e, 0x00, 0x1f, 0x80, 0x00,0x00, 0x1e, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x02,0x38, 0x1e, 0x00, 0x00, 0x00, 0x07, 0xfc, 0x1c,0x00, 0x20, 0x00, 0x07, 0xfc, 0x18, 0x00, 0x20,0x00, 0x1f, 0x0c, 0x10, 0x00, 0x20, 0x00, 0x7c,0x04, 0x1

16、0, 0x00, 0x60, 0x01, 0xf0, 0x00, 0x10,0x00, 0x60, 0x01, 0xe0, 0x00, 0x08, 0x00, 0xf0,0x00, 0x80, 0x00, 0x08, 0x03, 0xf0, 0x00, 0x00,0x00, 0x07, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x07,0xff, 0xf0, 0x00, 0x00, 0x00, 0x03, 0xff, 0xe0,0x00, 0x00, 0x00, 0x01, 0xff, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x0

17、0, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ;char tun48h =0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00,

18、0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e,0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00,0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00,0x03, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00,0

19、x00, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00,0x00, 0x01, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x03,0xf8, 0x00, 0x40, 0x00, 0x00, 0x00, 0x06, 0x07,0xc0, 0x00, 0x00, 0x00, 0x07, 0xff, 0xe0, 0x00,0x00, 0x00, 0x07, 0xff, 0xe0, 0x00, 0x00, 0x00,0x0f, 0xff, 0x80, 0x00, 0x00, 0x00, 0x7f, 0xf8,0x00, 0x00, 0x00, 0

20、x1f, 0xff, 0xf8, 0x00, 0x00,0x00, 0x1f, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x1f,0xfc, 0x3c, 0x00, 0x00, 0x00, 0x0f, 0xf8, 0x0e,0x00, 0x00, 0x00, 0x04, 0x70, 0x07, 0x00, 0x00,0x00, 0x00, 0x60, 0x03, 0x80, 0x00, 0x00, 0x00,0xc0, 0x00, 0xc0, 0x00, 0x00, 0x01, 0x80, 0x00,0x30, 0x00, 0x00, 0x01, 0x00, 0x3c, 0

21、x18, 0x00,0x00, 0x02, 0x03, 0xff, 0x0c, 0x00, 0x00, 0x0c,0x7f, 0xff, 0x8e, 0x00, 0x00, 0x18, 0xff, 0xff,0xc7, 0x80, 0x00, 0x78, 0xfe, 0x07, 0x87, 0xe0,0x01, 0xf0, 0x70, 0x07, 0x03, 0xf8, 0x07, 0xe0,0x70, 0x0e, 0x03, 0xfe, 0x00, 0x00, 0x38, 0x1e,0x01, 0xfe, 0x00, 0x00, 0x3f, 0xfe, 0x00, 0x0c,0x00, 0x

22、00, 0x1f, 0xfe, 0x00, 0x00, 0x00, 0x00,0x1f, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xfe,0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x

23、00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ;char dan48h =0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00,

24、 0x00, 0x00, 0x00,0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff,0x00, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0x80, 0x00,0x00, 0x03, 0xff, 0x80, 0x40, 0x00, 0x00, 0x01,0xf1, 0x80, 0x40, 0x00, 0x00, 0x01, 0x81, 0x80,0xe0, 0x00, 0x00, 0x00, 0x01, 0x93, 0xf0, 0x00,0x00, 0x00, 0x01, 0xff, 0xf0, 0x00, 0x00, 0x00,

25、0x21, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x21, 0xf8,0x00, 0x00, 0x00, 0x00, 0x61, 0xc0, 0x00, 0x00,0x00, 0x00, 0x61, 0x80, 0x00, 0x00, 0x00, 0x00,0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00,0x00, 0x00, 0x00, 0x01, 0xff, 0xc0, 0x00, 0x00,0x00, 0x03, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x02,0x00, 0xfc, 0x00,

26、0x00, 0x00, 0x04, 0x02, 0x1f,0x00, 0x00, 0x00, 0x08, 0x03, 0x01, 0xc0, 0x00,0x00, 0x38, 0x03, 0x00, 0x7c, 0x00, 0x00, 0xf8,0x07, 0xf8, 0x3f, 0xc0, 0x01, 0xf0, 0x3f, 0xfe,0x3f, 0xf8, 0x03, 0xc1, 0xff, 0x0f, 0x1f, 0xf8,0x00, 0x01, 0xe3, 0x0f, 0x0f, 0xf0, 0x00, 0x01,0xc3, 0x0e, 0x00, 0x00, 0x00, 0x01,

27、0x83, 0xfc,0x00, 0x00, 0x00, 0x00, 0xc7, 0xf8, 0x00, 0x00,0x00, 0x00, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00,0x7f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x03,0x80, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x00,0x00, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00,0x1f, 0xf8, 0x20, 0x00, 0x00, 0x00, 0xff, 0xff,0xe0, 0

28、x00, 0x00, 0x07, 0xff, 0x81, 0xe0, 0x00,0x00, 0x07, 0xe0, 0x00, 0xe0, 0x00, 0x00, 0x03,0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0

29、x00, 0x00, 0x00, 0x00,;char zuo16h =0x18, 0xc0, 0x18, 0xc0, 0x19, 0x80, 0x31, 0xfe,0x33, 0xfe, 0x76, 0xc0, 0xf0, 0xfc, 0xb0, 0xfc,0x30, 0xc0, 0x30, 0xc0, 0x30, 0xfe, 0x30, 0xfe,0x30, 0xc0, 0x30, 0xc0, 0x30, 0xc0, 0x00, 0x00, ;char zhe16h =0x03, 0x00, 0x03, 0x0c, 0x1f, 0xcc, 0x1f, 0xd8,0x03, 0x30, 0x

30、ff, 0xfe, 0xff, 0xfe, 0x03, 0x00,0x0f, 0xf8, 0x3f, 0xf8, 0xec, 0x18, 0xcf, 0xf8,0x0c, 0x18, 0x0f, 0xf8, 0x0f, 0xf8, 0x00, 0x00, ;char tian16h =0x00, 0x00, 0x3f, 0xfc, 0x3f, 0xfc, 0x31, 0x8c,0x31, 0x8c, 0x31, 0x8c, 0x3f, 0xfc, 0x3f, 0xfc,0x31, 0x8c, 0x31, 0x8c, 0x31, 0x8c, 0x3f, 0xfc,0x3f, 0xfc, 0x30

31、, 0x0c, 0x00, 0x00, 0x00, 0x00, ;char xue16h =0x33, 0x18, 0x19, 0x98, 0x08, 0xb0, 0x7f, 0xfc,0x7f, 0xfc, 0x60, 0x0c, 0x1f, 0xf0, 0x1f, 0xf0,0x00, 0xc0, 0x7f, 0xfc, 0x7f, 0xfc, 0x01, 0x80,0x01, 0x80, 0x07, 0x80, 0x03, 0x00, 0x00, 0x00, ;char ke16h =0x00, 0x00, 0x0c, 0x18, 0xfd, 0x98, 0xf8, 0xd8,0x18,

32、 0x58, 0xfe, 0x18, 0xfe, 0x98, 0x18, 0xd8,0x3c, 0x58, 0x7e, 0x1e, 0xdb, 0xfe, 0x9b, 0xf8,0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, ;struct food/* 定義結(jié)構(gòu)體存儲食物的屬性*/int x; /* 食物的坐標 */int y;int yes; /* 值為 0 表示屏幕上沒有食物,值為 1 表示屏幕上有食 物 */int color; /* 食物顏色 */ food;struct snake/* 定義結(jié)構(gòu)體存儲蛇的屬性*/int xn; /*

33、每一節(jié)蛇的坐標 */int yn;int colorn;/* 存儲每一節(jié)蛇的顏色*/int node; /* 蛇的節(jié)數(shù) */int direction; /* 蛇移動的方向 */int life; /* 蛇的生命,如果為 1,蛇死,游戲結(jié)束 */ snake;void init(void)/*圖形驅(qū)動*/int driver = detect, mode = 0;registerbgidriver(egavga_driver);initgraph(&driver, &mode, );void drawmat(char *mat, int matsize, int x, int y, int c

34、olor) /* 漢字點陣*/int i, j, k, m;m = (matsize - 1) / 8 + 1;for(j = 0; j matsize; j+)for(i = 0; i m; i+)for(k = 0; k k)putpixel(x + i * 8 + k, y +j, color);void showword(void)/* 調(diào)用漢字點陣輸出程序,顯示標題和作者信息 */drawmat(cai48h, 48, 249, -4, 7);drawmat(she48h, 48, 329, -4, 7);drawmat(tun48h, 48, 409, -4, 7);drawmat

35、(dan48h, 48, 489, -4, 7);drawmat(cai48h, 48, 250, -5, 4);drawmat(she48h, 48, 330, -5, 4);drawmat(tun48h, 48, 410, -5, 4);drawmat(dan48h, 48, 490, -5, 4); /*作者 田學科*/drawmat(zuo16h, 16, 515, 465, 7);drawmat(zhe16h, 16, 530, 465, 7);drawmat(tian16h, 16, 550, 465, 7);drawmat(xue16h, 16, 565, 465, 7);dra

36、wmat(ke16h, 16, 580, 465, 7);void draw(void)/*畫出四周的墻*/if(color = 15)color = 0;setcolor(+color);setlinestyle(solid_line, 0, 1);for(i = 30; i = 600; i += 10)rectangle(i, 40, i + 10, 49);rectangle(i, 451, i + 10, 460);for(i = 40; i 450; i += 10)rectangle(30, i, 39, i + 10);rectangle(601, i, 610, i + 10

37、);void prscore(void)/* 打印游戲分數(shù) */char str10;setfillstyle(solid_fill, yellow);bar(50, 10, 200, 30);setcolor(6);settextstyle(0, 0, 2);sprintf(str, score:%d, score);outtextxy(55, 15, str);void gameover(void)cleardevice(); /* 清屏函數(shù) */for(i = 0; i ; i+) /* 畫出蛇死時的位置 */ setcolori);rectanglei, i, i + 10, i +

38、10);prscore(); /* 顯示分數(shù) */draw();showword();settextstyle(0, 0, 6);setcolor(7);outtextxy(103, 203, game over);setcolor(red);outtextxy(100, 200, game over);void gameplay(void)/* 玩游戲的具體過程 */ int flag, flag1;randomize();prscore();gamespeed = 50000;= 0; /* =0 表示屏幕上沒有食物 */= 1; /* =1 表示蛇是活著的 */= 4; /* 表示蛇的初

39、始方向為向右 */= 2; /* 蛇的初始化為兩節(jié) */0 = 2; /* 兩節(jié)蛇頭初始化為綠色*/1 = 2;0 = 100;0 = 100;1 = 110;1 = 100;= random(15) + 1;while(1)while(1)if = 0) /* 如果蛇活著 */while(1)flag = 1;= 1;= random(56) * 10 + 40;= random(40) * 10 + 50;for(i = 0; i 0; i-) i = i-1;i = i-1;switchcase 1:0 -= 10;break;case 2:0 += 10;break;case 3:0

40、-= 10;break;case 4:0 += 10;break;for(i = 3; i ; i+)ifi = 0 & i = 0) gameover();= 0;break;if0 590 | 0 440)gameover();= 0;if = 0)break;if0 = & 0 = /*蛇吃掉食物 */ setcolor(0);rectangle, , + 10, + 10); = -20; = -20; = ;+;= 0;= random(15) + 1;score += 10;prscore();if(score % 100 = 0 & score != 0) for(i = 0;

41、i ; i+) /* 畫出蛇 */setcolori);rectanglei, i,i + 10, i + 10);sound(200);delay(50000);delay(50000);delay(50000);delay(50000);delay(50000);delay(50000);nosound();gamespeed -= 5000;draw();elsesound(500);delay(500);nosound();for(i = 0; i ; i+) /* 畫出蛇 */setcolori);rectanglei, i, i + 10, i +10);delay(gamespe

42、ed);delay(gamespeed);flag1 = 1;setcolor(0);rectangle, , + 10, + 10);if(kbhit() & flag1 = 1) /* 如果沒按有效鍵就重新開始循環(huán)*/flag1 = 0;key = bioskey(0);if(key = esc)exit(0);else if(key = up & != 2)= 1;else if(key = down & != 1)= 2;else if(key = left & != 4)= 3;else if(key = right & != 3)= 4;if = 0) /* 如果蛇死了就退出循環(huán)*

43、/break;void main(void)while(1)color = 0;init();cleardevice();showword();draw();gameplay();setcolor(15);settextstyle(0, 0, 2);outtextxy(200, 400, continue(y/n);while(1)key = bioskey(0);if(key = y | key = n | key = esc)break;if(key = n | key = esc)break;closegraph();3、 c 語言實現(xiàn)移動電話系統(tǒng)#include #define gri

44、d-size 5#define selected -1 /* 低于矩陣 中所有元素*/#define traffic-file “”/*關(guān)于交通數(shù)據(jù)的文件*/ #define num-transmitters 10 /*可用的發(fā)射器數(shù)量*/void get-traffic-data(int commutersgrid-sizegrid-size,intsalesforcegrid-sizegrid-size,int weekendsgrid-sizegrid-size;voide print-matrixgrid-sizegrid-size;intmain(void)int commuters

45、grid-sizegrid-size;/* 上午 8:30 的交通 數(shù)據(jù)*/int salesforcegrid-sizegrid-size; /*上午 11:00 的交通數(shù)據(jù)*/int weekendgrid-sizegrid-size;/*周末交通數(shù)據(jù)*/int commuter-weight, /* 通勤人員數(shù) 據(jù)的權(quán)重因子*/sale-weight,/*營銷人員數(shù)據(jù)的權(quán)重因子*/weekend-weight; /*周末數(shù)據(jù)的權(quán)重因子*/int location-i, /*每個發(fā)射器的位置 */location-j;int current-max; /*和數(shù)據(jù)中當前的最大值*/int i

46、,j, /*矩陣的循環(huán)計數(shù)器*/tr; /*發(fā)射器的循環(huán)計數(shù)器*/*填入并顯示交通數(shù)據(jù)*/get-traffic-data (commuters,salesforce,weekend);printf(“8:、nn”)print-matrix(commuters);printf(“nn weekend traffic datann”); print-matrix(salesforce);printf(“nn weekend traffic datann”); printf_matrix(weekeng);/*請用戶輸入權(quán)重因子*/printf(“nnplease input the follow

47、ing value:n”);printf(“weight (an interger=0) for the 8:30 data”) scanf(“%d”,&commuter_weight);printf(“weight(an integer=0) for the weekeng data”); scanf(“%d”,&weekend_weight);scanf(“%d”,&weekend_weight);/*計算并顯示加權(quán)后求和的數(shù)據(jù)*/for (i=0;igrid_size;+i)for (j=0;jgrid_size;+j)summed_dataij=commuter_weight*comm

48、uterij+salesforce_weight*salesforceij+weekend_weight*weekendij;printf(“nnthe weighted,summed data is :nn”); printf_matrix(summed_data);/*在 summed_data 矩陣中找出 num_transmitters 個最大值,將坐標臨時存儲在 location_i 和 location_j 中,然后把最后的結(jié)果坐標輸出*/printf(“nnlocations of the %d transmitters:nn”,num_transmitters);for (tr=1;tr=num_transmitters;+tr)current_max=selected;/*以一個過低的值為起點開始查找*/for (i=0;igrid_size;+i)for(j=0;jgrid_size;+j)if(current_maxsummed_dat

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論