小編程展示
switch()
case:
..........
⑵ 怎樣做小游戲和編程
使用類編程思路清晰,可讀性強,本例通過編寫貪吃蛇展示類的基本應用。最終效果如下:網頁教學網:本文中全部的Fla源碼在文章最後全部打包供大家下載研究學習使用。看不懂鏈接名等內容的,可以看我的另一個教程「 簡單射擊游戲教程 」,或許有所幫助。全部源文件如下:貪吃蛇—類編程.rar第一步:「蛇」類初始化 新建fla文件,同目錄下新建as文件,取名Snake.as,類名必須和文件名相同。fla文件中新建蛇節點元件,鏈接名為node,第一幀和類中寫入相應代碼。
第一步:「蛇」類初始化.rar第二步:蛇的移動 寫個move方法,在init方法中設置時間間隔。
第二步:蛇的移動.rar第三步: 鍵盤改變移動方向 寫個changeDirection方法,在主場景第一幀用鍵盤事件調用該方法,控制蛇的方向。
第三步:鍵盤改變移動方向.rar第四步:增加節點 寫個addNode方法,新節點產生在蛇尾即nodes[length - 1]的位置上,暫時加個按鈕調用addNode方法,觀察結果。
第四步:增加節點.rar第五步:碰撞判斷 修改move方法,假如頭節點與蛇身其他部位重合,clearInterval刪除move的定時調用。同時changeDirection也要加多個判斷,不能讓頭節點和第二節點重合,加多這個判斷是為了防止一個Bug的產生,一些貪吃蛇程序並沒有注意到這點。這個Bug產生原因如下:
假設蛇向右移動,是不能進行向左改變方向,但由於move方法是定時調用的,比如每300毫秒一次,所以在這300毫秒內可能進行了多次快速按鍵。第一次按向下,蛇的xDirection和yDirection改變為向下,但move的執行時間沒到,又緊接著按左,因為蛇方向在數據上已經改變,所以捕捉不到不能向左的判斷,快速按鍵造成蛇反向移動的Bug就產生了,加個上述判斷就好了。
第五步:碰撞判斷.rar第六步:食物類編寫 新建Food類,注意用extends繼承MovieClip,這樣元件才能鏈接它,在主場景中新建食物元件,鏈接Food類,實例名為food,拖入場景。在Food中寫入appear和disappear方法,做兩個臨時按鍵調用它們觀察效果。
第六步:食物類編寫.rar最終完成:吃食物 Food中定時調用appear,並通過setSnake引入Snake實例snake,判斷蛇身坐標不讓新食物與之重合。Snake中通過setFood引入Food實例food,判斷是否吃到食物,做出相應處理,如食物消失,增加蛇節點,改變setSnake。場景第一幀也要setSnake引入蛇頭。 以後還要增加新功能,如阻礙物設置等,都可以通過改變as文件完成。雖然類編程比直接控制影片較為繁瑣,但由於使用了面向對象,以後再對程序進行完善時都可依照對象行為思考,每個方法就是對象的每個行為,什麼行為需要改變就找對應的方法修改,思路清晰。
⑶ 電腦小編程
很用得到!
實際工作中,可能領導會要求你一上午就完成10萬個這樣的需求。你不但要會做這種需求,還要會高速度完成。否則就像有些人一樣,老了,新來的人一天能做1億個需求,有些人根不上了,面臨裁員。
⑷ 求簡單短節的小游戲編程
#include <graphics.h>
#include <stdlib.h>
#include <dos.h>
#include <conio.h>
#include <bios.h>
#define KEY_ESC 0x01
#define KEY_SPACE 0x39
#define KEY_UP 0x48
#define KEY_LEFT 0x4b
#define KEY_RIGHT 0x4d
#define KEY_DOWN 0x50
/*1石頭,2磚塊,3水,5老家,8玩家,9敵人*/
int map[20][20]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,2,2,2,2,0,0,2,2,2,2,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,2,0,0,2,0,1,1,1,1,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,2,2,2,2,2,2,2,0,0,0,0,0,0,0,2,2,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,0,1,
1,0,1,1,1,1,3,3,3,3,0,0,0,0,0,0,0,2,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,3,3,3,0,1,
1,0,0,0,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,3,3,3,1,1,1,1,1,1,1,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,2,2,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,1,
1,0,2,2,0,0,0,0,2,2,2,0,0,0,2,2,0,0,0,1,
1,0,0,0,0,0,0,8,2,5,2,0,0,0,0,0,0,0,0,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
struct f
{
int x;
int y;
int direction;
};
struct play
{
int x;/*行坐標*/
int y;/*列坐標*/
int direction;/*方向*/
struct f fire[5];/*5顆子彈*/
int score;/*分數*/
}Playone;
struct a
{
int x;
int y;
int color;
int direction;
int directiontwo;/*用來判斷走的路是否往返*/
int fireplay;/*是否攻擊的變數,隨機生成*/
struct f fire;
}amy[5];/*敵人的結構體,其實可以添加不同的顏色來表示不同種類的坦克*/
char key_state[128],key_pressed[128];
void Init();/*圖象驅動開始*/
void End();/*圖象驅動結束*/
void DrawMap();/*畫地圖*/
void DrawWater(int x,int y);/*畫水*/
void DrawBrick(int x,int y);/*畫磚*/
void DrawTone(int x,int y);/*畫石頭*/
void DrawHome(int x,int y);/*畫老家*/
void DrawBlack(int x,int y);/*去除內容*/
void DrawPlay(int x,int y);/*畫玩家*/
void DrawAmy(int x,int y,int i);/*畫敵人*/
void Score();/*輸出分數*/
void GamePlay();/*玩游戲過程*/
void GameOver();/*游戲失敗*/
void TimeDelay(unsigned long microsec); /*延時函數 傳入微秒數*/
int GetKey(int ScanCode);/*這里開始都是按鍵函數*/
void interrupt far (*OldInt9Handler)();
void far interrupt NewInt9();
void InstallKeyboard();
void ShutDownKeyboard();
void main(void)
{
Init();
DrawMap();
GamePlay();
End();
}
void TimeDelay(unsigned long microsec) /*延時函數 傳入微秒數*/
{
union REGS r;
r.h.ah=0x86;
r.x.cx=microsec>>16;
r.x.dx=microsec;
int86(0x15,&r,&r);
}
void Init()/*圖象驅動開始*/
{int gd=DETECT,gm;
initgraph(&gd,&gm,"d:\\tc\\tc");
cleardevice();
InstallKeyboard();
}
void End()/*圖象驅動結束*/
{
ShutDownKeyboard();
closegraph();
}
void DrawTone(int x,int y)/*畫石頭*/
{
setfillstyle(SOLID_FILL,7);
bar(100+x*20-9,50+y*20-9,100+x*20+9,50+y*20+9);
}
void DrawWater(int x,int y)/*畫水*/
{
setfillstyle(SOLID_FILL,BLUE);
bar(100+x*20-9,50+y*20-9,100+x*20+9,50+y*20+9);
}
void DrawBrick(int x,int y)/*畫磚*/
{
setfillstyle(SOLID_FILL,6);
bar(100+x*20-9,50+y*20-9,100+x*20+9,50+y*20+9);
setcolor(15);
line(100+x*20-9,50+y*20-4,100+x*20+9,50+y*20-4);
line(100+x*20-9,50+y*20+4,100+x*20+9,50+y*20+4);
line(100+x*20-4,50+y*20-9,100+x*20-4,50+y*20+9);
line(100+x*20+4,50+y*20-9,100+x*20+4,50+y*20+9);
}
void DrawHome(int x,int y)/*畫老家*/
{
setcolor(0);
setfillstyle(SOLID_FILL,GREEN);
fillellipse(100+x*20,50+y*20,9,9);
}
void DrawBlack(int x,int y)/*去除內容*/
{
setcolor(0);
setfillstyle(SOLID_FILL,0);
bar(100+x*20-9,50+y*20-9,100+x*20+9,50+y*20+9);
}
void DrawPlay(int x,int y)/*畫玩家*/
{
setcolor(4);/*玩家為紅色*/
circle(100+x*20,50+y*20,7);
switch(Playone.direction)/*判斷玩家方向*/
{
case 1:line(100+x*20,50+y*20,100+x*20,50+y*20-9);break;/*上*/
case 2:line(100+x*20,50+y*20,100+x*20+9,50+y*20);break;/*右*/
case 3:line(100+x*20,50+y*20,100+x*20,50+y*20+9);break;/*下*/
case 4:line(100+x*20,50+y*20,100+x*20-9,50+y*20);break;/*左*/
}
}
void DrawAmy(int x,int y,int i)/*畫敵人*/
{
if(amy.color==12)
setcolor(12);
else if(amy.color==13)
setcolor(13);
else/*這里是判斷三種顏色的坦克*/
setcolor(14);
circle(100+x*20,50+y*20,7);
switch(amy.direction)/*判斷玩家方向*/
{
case 1:line(100+x*20,50+y*20,100+x*20,50+y*20-9);break;/*上*/
case 2:line(100+x*20,50+y*20,100+x*20+9,50+y*20);break;/*右*/
case 3:line(100+x*20,50+y*20,100+x*20,50+y*20+9);break;/*下*/
case 4:line(100+x*20,50+y*20,100+x*20-9,50+y*20);break;/*左*/
}
}
void Score()/*輸出分數*/
{
char s[10];
Playone.score+=10;
sprintf(s,"%d",Playone.score);
setfillstyle(SOLID_FILL,0);
bar(550,100,640,130);
settextstyle(0,0,2);
setcolor(YELLOW);
outtextxy(550,115,s);
}
void DrawMap()/*畫地圖*/
{int i,j,k;
for(i=0;i<20;i++)
{
for(j=0;j<20;j++)
if(map[j]==1)
DrawTone(j,i);
else if(map[j]==2)
DrawBrick(j,i);
else if(map[j]==3)
DrawWater(j,i);
else if(map[j]==5)
DrawHome(j,i);
else if(map[j]==8)
{
Playone.x=i;
Playone.y=j;
Playone.direction=1;
DrawPlay(j,i);
for(k=0;k<5;k++)
Playone.fire[k].direction=-1;/*5顆子彈的方向都為-1,表示不存在*/
}
else if(map[j]==9)
{
amy[0].x=1;amy[0].y=1;amy[0].direction=amy[0].directiontwo=3;/*第一個敵人*/
amy[0].color=12;
DrawAmy(j,i,0);
}
}
for(i=1;i<5;i++)/*敵人都沒出現*/
amy.direction=amy.fire.direction=-1;
outtextxy(210,450,"2003.10.1 milo_zy");
settextstyle(0,0,2);/*首次輸出得分*/
setcolor(9);
outtextxy(525,80,"Score");
setcolor(YELLOW);
outtextxy(550,115,"0");
}
void far interrupt NewInt9(void)
{
unsigned char ScanCode,temp;
ScanCode=inportb(0x60);
temp=inportb(0x61);
outportb(0x61,temp | 0x80);
outportb(0x61,temp & 0x7f);
if(ScanCode&0x80)
{
ScanCode&=0x7f;
key_state[ScanCode]=0;
}
else
{
key_state[ScanCode]=1;
key_pressed[ScanCode]=1;
}
outportb(0x20,0x20);
}
void InstallKeyboard(void)
{
int i;
for(i=0;i<128;i++)
key_state=key_pressed=0;
OldInt9Handler=getvect(9); /*中斷向量值*/
setvect(9,NewInt9); /*中斷程序NewInt9地址存入指定的中斷向量表中INT 09H*/
}
void ShutDownKeyboard(void)
{
setvect(9,OldInt9Handler);
}
int GetKey(int ScanCode)
{
int res;
res=key_state[ScanCode]|key_pressed[ScanCode];
key_pressed[ScanCode]=0;
return res;
}
void GameOver()/*游戲失敗*/
{
setcolor(0);
setfillstyle(SOLID_FILL,0);/*把老家給去除*/
fillellipse(100+9*20,50+18*20,9,9);
nosound();
setcolor(RED);
settextstyle(0,0,4);
outtextxy(150,5,"GAME OVER");
while(1)
{
if(GetKey(KEY_ESC))
break;
}
}
void GamePlay()/*玩游戲的過程*/
{
int i,j,lose=0;/*lose是1的時候表示失敗*/
int t=0;
randomize();
while(1)
{
for(i=0;i<5;i++)/*畫敵人的子彈*/
{
if(amy.fire.direction>0)
putpixel(100+amy.fire.y*20,50+amy.fire.x*20,11);
}
for(i=0;i<=4;i++)/*畫玩家子彈*/
{
if(Playone.fire.direction>0)/*大於0表示玩家子彈存在*/
putpixel(100+Playone.fire.y*20,50+Playone.fire.x*20,11);
}
TimeDelay(500000);/*關鍵的時間改動*/
for(i=0;i<5;i++)/*去敵人的子彈*/
{
if(amy.fire.direction>0)
putpixel(100+amy.fire.y*20,50+amy.fire.x*20,0);
}
for(i=0;i<=4;i++)/*去玩家除子彈*/
{
if(Playone.fire.direction>0)
putpixel(100+Playone.fire.y*20,50+Playone.fire.x*20,0);
}
for(i=0;i<=4;i++)/*玩家子彈位置的變化*/
{
if(Playone.fire.direction<0)
continue;
if(Playone.fire.direction==1)
{Playone.fire.x--;Playone.fire.y=Playone.fire.y;}
else if(Playone.fire.direction==2)
{Playone.fire.y++;Playone.fire.y=Playone.fire.y;}
else if(Playone.fire.direction==3)
{Playone.fire.x++;Playone.fire.y=Playone.fire.y;}
else if(Playone.fire.direction==4)
{Playone.fire.y--;Playone.fire.y=Playone.fire.y;}
/*打到石頭或者磚頭的情況下減少子彈*/
if(map[Playone.fire.x][Playone.fire.y]==1)/*打到石頭*/
Playone.fire.direction=-1;/*子彈消失*/
if(map[Playone.fire.x][Playone.fire.y]==2)/*打到磚頭*/
{
Playone.fire.direction=-1;
DrawBlack(Playone.fire.y,Playone.fire.x);/*磚頭打掉*/
map[Playone.fire.x][Playone.fire.y]=0;/*被打掉的地方變成可走的地方*/
}
if(map[Playone.fire.x][Playone.fire.y]==5)/*自己打到老家*/
{lose=1;break;}
for(j=0;j<5;j++)
{
if(amy[j].direction<0)/*不存在的不判斷*/
continue;
if(amy[j].x==Playone.fire.x&&amy[j].y==Playone.fire.y)/*打中敵人*/
{
Playone.fire.direction=-1;
DrawBlack(Playone.fire.y,Playone.fire.x);
map[Playone.fire.x][Playone.fire.y]=0;/*被打掉的地方變成可走的地方*/
amy[j].fire.direction=amy[j].direction=-1;/*這個敵人消失*/
Score();/*輸出得分*/
}
}
}
for(i=0;i<5;i++)/*敵人子彈位置的變化*/
{
if(amy.direction<0||amy.fire.direction<0)
continue;
if(amy.fire.direction==1)
{amy.fire.x--;amy.fire.y=amy.fire.y;}
else if(amy.fire.direction==2)
{amy.fire.y++;amy.fire.x=amy.fire.x;}
else if(amy.fire.direction==3)
{amy.fire.x++;amy.fire.y=amy.fire.y;}
else if(amy.fire.direction==4)
{amy.fire.y--;amy.fire.x=amy.fire.x;}
/*打到石頭或者磚頭的情況下減少子彈*/
if(map[amy.fire.x][amy.fire.y]==1)/*打到石頭*/
amy.fire.direction=-1;/*子彈消失*/
if(map[amy.fire.x][amy.fire.y]==2)/*打到磚頭*/
{
amy.fire.direction=-1;
DrawBlack(amy.fire.y,amy.fire.x);/*磚頭打掉*/
map[amy.fire.x][amy.fire.y]=0;/*被打掉的地方變成可走的地方*/
}
if(map[amy.fire.x][amy.fire.y]==5)/*敵人打到老家*/
{lose=1;break;}
if(amy.fire.x==Playone.x&&amy.fire.y==Playone.y)/*打中玩家*/
{
for(j=0;j<5;j++)
Playone.fire[j].direction=-1;/*玩家子彈都消失*/
amy.fire.direction=-1;
DrawBlack(amy.fire.y,amy.fire.x);
map[amy.fire.x][amy.fire.y]=0;/*被打掉的地方變成可走的地方*/
lose=1;break;/*好人被打掉後就失敗*/
}
}
nosound();
for(i=0;i<5;i++)/*敵人方向隨機的改變*/
{
if(amy.direction<0)
continue;
while(1)
{
amy.directiontwo=random(4)+1;
if(amy.direction==1&&amy.directiontwo==3)
continue;
if(amy.direction==3&&amy.directiontwo==1)
continue;
if(amy.direction==2&&amy.directiontwo==4)
continue;
if(amy.direction==4&&amy.directiontwo==2)/*這里4個if是判斷有沒有往返走*/
continue;
if(amy.directiontwo==3&&(map[amy.x+1][amy.y]==3||map[amy.x+1][amy.y]==1||map[amy.x+1][amy.y]==2))
continue;
if(amy.directiontwo==1&&(map[amy.x-1][amy.y]==3||map[amy.x-1][amy.y]==1||map[amy.x-1][amy.y]==2))
continue;
if(amy.directiontwo==2&&(map[amy.x][amy.y+1]==3||map[amy.x][amy.y+1]==1||map[amy.x][amy.y+1]==2))
continue;
if(amy.directiontwo==4&&(map[amy.x][amy.y-1]==3||map[amy.x][amy.y-1]==1||map[amy.x][amy.y-1]==2))
continue;/*以上4個是是否碰到了牆壁或者水什麼的*/
DrawBlack(amy.y,amy.x);/*把原來的地方擦掉*/
amy.direction=amy.directiontwo;
if(amy.direction==1)
{amy.x--;amy.y=amy.y;}
if(amy.direction==3)
{amy.x++;amy.y=amy.y;}
if(amy.direction==2)
{amy.y++;amy.x=amy.x;}
if(amy.direction==4)
{amy.y--;amy.x=amy.x;}
if(amy.x==Playone.x&&amy.y==Playone.y)/*相撞*/
lose=1;
if(map[amy.x][amy.y]==5)/*敵人撞到老家*/
lose=1;
DrawAmy(amy.y,amy.x,i);/*畫敵人*/
if(amy.fire.direction<0)
amy.fireplay=random(4);
if(amy.fireplay==1&&amy.fire.direction<0)/*發射*/
{
amy.fire.direction=amy.direction;/*子彈方向與敵人方向一致*/
amy.fire.x=amy.x;
amy.fire.y=amy.y;
}
break;
}
}
if(lose)/*因為失敗而跳出循環顯示失敗*/
{GameOver();break;}
if(GetKey(KEY_ESC))
break;
if(GetKey(KEY_UP))/*往上*/
{
if(Playone.direction==1&&map[Playone.x-1][Playone.y]!=1&&map[Playone.x-1][Playone.y]!=2)
{
if(map[Playone.x-1][Playone.y]==3)
continue;
DrawBlack(Playone.y,Playone.x);/*這個if是移動,前提是方向與按下的到向一致*/
Playone.x--;
Playone.direction=1;
DrawPlay(Playone.y,Playone.x);
}
else/*只調整炮頭方向*/
{
DrawBlack(Playone.y,Playone.x);
Playone.direction=1;
DrawPlay(Playone.y,Playone.x);
}
}
else if(GetKey(KEY_DOWN))/*往下*/
{
if(Playone.direction==3&&map[Playone.x+1][Playone.y]!=1&&map[Playone.x+1][Playone.y]!=2)
{
if(map[Playone.x+1][Playone.y]==3)
continue;
DrawBlack(Playone.y,Playone.x);
Playone.x++;
Playone.direction=3;
DrawPlay(Playone.y,Playone.x);
}
else
{
DrawBlack(Playone.y,Playone.x);
Playone.direction=3;
DrawPlay(Playone.y,Playone.x);
}
}
if(GetKey(KEY_RIGHT))/*往右*/
{
if(Playone.direction==2&&map[Playone.x][Playone.y+1]!=1&&map[Playone.x][Playone.y+1]!=2)
{
if(map[Playone.x][Playone.y+1]==3)
continue;
DrawBlack(Playone.y,Playone.x);
Playone.y++;
Playone.direction=2;
DrawPlay(Playone.y,Playone.x);
}
else
{
DrawBlack(Playone.y,Playone.x);
Playone.direction=2;
DrawPlay(Playone.y,Playone.x);
}
}
if(GetKey(KEY_LEFT))/*往左*/
{
if(Playone.direction==4&&map[Playone.x][Playone.y-1]!=1&&map[Playone.x][Playone.y-1]!=2)
{
if(map[Playone.x][Playone.y-1]==3)
continue;
DrawBlack(Playone.y,Playone.x);
Playone.y--;
Playone.direction=4;
DrawPlay(Playone.y,Playone.x);
}
else
{
DrawBlack(Playone.y,Playone.x);
Playone.direction=4;
DrawPlay(Playone.y,Playone.x);
}
}
if(GetKey(KEY_SPACE))/*發射子彈*/
{
for(i=0;i<5;i++)/*用循環來找是否有子彈可以用*/
if(Playone.fire.direction<0)
{
sound(300);
Playone.fire.direction=Playone.direction;/*子彈方向與坦克方向一致*/
Playone.fire.x=Playone.x;
Playone.fire.y=Playone.y;
break;/*找到後就跳出循環*/
}
}
if(map[Playone.x][Playone.y]==5)/*玩家自己撞到老家*/
lose=1;
for(i=0;i<5;i++)/*判斷是否因自己控制撞到敵人*/
{
if(amy.direction<0)
continue;
if(amy.x==Playone.x&&amy.y==Playone.y)/*相撞*/
lose=1;
}
if(lose)/*因為失敗而跳出循環顯示失敗*/
{GameOver();break;}
t++;/*加到一定的程序就出現新的敵人*/
if(t==30) /*到了增加敵人的時候*/
{t=0;
for(i=0;i<5;i++)
if(amy.direction<0)
{
amy.direction=amy.directiontwo=3;
amy.x=1;
amy.y=random(3);/*方向隨機*/
if(amy.y==0)
amy.y=1;
else if(amy.y==1)
amy.y=9;
else/*這里和上面的兩個判斷是判斷敵人的初始位置*/
amy.y=18;
amy.color=random(3)+12;/*顏色隨機*/
DrawAmy(amy.y,amy.x,i);
break;/*找到一個後就出循環*/
}
}
}
}
⑸ C語言小編程
#include <stdio.h>
int main(){
int n,i,sum;
for (n=1;n<=1000;n++)
{sum=0; for (i=1;i<n;i++) {if (n%i==0) sum=sum+i; }
if (sum==n) {
printf("%d its factors are ",n);
sum=0; for (i=1;i<n;i++) if (n%i==0) printf("%d,",i);
printf("\b \n");
};
}
return 0;
}
注意逗號的輸出。printf("\b \n"); 是刪去最後一個多餘的逗號。輸出:
6 its factors are 1,2,3
28 its factors are 1,2,4,7,14
496 its factors are 1,2,4,8,16,31,62,124,248
⑹ 我想學一些PLC簡單的編程,編了一些小程序,怎麼演示正確與否。哪有演示軟體
這個是純邏輯的編程,可以用plc的模擬軟體,可以用
三菱模擬軟體GX-Simulator和GX-Developer 兩個是安裝在一起的一起用的,用GX-Developer 編寫程序 ,用 GX-Simulator模擬 。可以看到 X** Y**的閉合情況,完全可以模擬你的程序 ,搜索這個軟體下載試試 ,呵呵 祝你進步 。
⑺ C語言小編程....
#include<stdio.h>
main()
{
unsigned
long
i,a,b;
a=0;
for(i=1;i<=3000000;i++)
{
a=a+i;
if(i%1000000==0)
printf("1+2+...+%ld=%ld\n",i,a);
}
}
但是,好象沒法表示這么大的數啊,最後的結果會另你意外,那是超過了他的表示範圍了.
⑻ 趣味C語言小編程
題眼就是求出2~10的最小公倍數,然後減一。
模擬排隊的演算法是可行的,但不是最優的。
#include <stdio.h>
int od(int x,int n) //x是否能被n整除,是返回1,否返回0
{
if (x%n) return 0;
return 1;
}
int gbs(int a[],int n) //求a[n]內所有元素的最小公倍數
{
int i,j,k,o,m=0;
int b[20],c[100];
for (i=0;i<n;i++)
{
if(m<a[i]) m=a[i];
b[i]=a[i];
}
j=2; o=0;
while (j<=m)
{
k=0;
for (i=0;i<n;i++){
if (od(b[i],j)) k++;
if (k>1) break;
}
if(k>1)
{
c[o++]=j;
for (i=0;i<n;i++)
if (od(b[i],j)) b[i]=b[i]/j;
m=0;
for (i=0;i<n;i++)
if(m<b[i]) m=b[i];
}
else
j++;
}
k=1;
for(i=0;i<o;i++)
{
k*=c[i];
}
for (i=0;i<n;i++)
{
k*=b[i];
}
return k;
}
main()
{
int a[10];
for(int i=1;i<=10;i++)
a[i-1]=i;
printf("count=%d\n",gbs(a,10)-1);
getchar();
return 0;
}
⑼ 一道簡單而奇怪+有趣的c++小編程!!
因為malloc和free函數是包含在命名空間STD 中的,如果去掉了命名空間,則申請空間那一句是沒有作用的,釋放空間那一句也沒有作用,str此時僅僅是被定義的一個空的字元串指針而且沒有初始化,而一旦去掉注釋行,str 此時申請了空間,雖然後來釋放了數據,但是因為它申請了空間,所以指針不為空,此時重新讀入world,然後輸出來
⑽ 做小程序需要學什麼編程,好做不
開發小程序需要的是編程基礎,需要學習的技術如下:
1、微信小程序wxml,這個語言的編程理念和html網頁的編程技術是類似的。
2、微信小程序之wxss,就是微信的css。微信把網頁編程里運用的css,換成了自己的開發語言,wxss,其實主要的實現思想理念也和網頁的開發技術基本沒什麼不同,也是一些標簽的簡單替換,大部分和原先的css、基本不誤。
3、微信小程序之js,如果你想開發一款微信小程序學會微信小程序的js是必須要精通的
4、微信小程序之json,簡單來說json就是微信小程序的一門主次的界面,工程師們可以通過json控制上下菜單欄、主次的頁面展示順序,不過用的頻率不高,只是在基本的小程序的框架構架才會應用到。
其實,小程序類似於H5面,提供了視圖層描述語言,需要掌握WXML 和 WXSS 以及基於JavaScript的邏輯層框架,這里wxml相當於html,wxss相當於css。