c游戲編程代碼大全,按所給的公式計算組合數并輸出結果?
代碼如下。
#include<stdio.h>
int prime[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 };
int len = 10;
int factors1[10];
int factors2[10];
void decompose(int* factors, int m, int n)
{
for (int i = 0; i < len; i++) factors[i] = 0;
for (int j = m; j <= n; j++)
{
int temp = j;
for (int t = 0; t < len; t++)
{
while (temp != 1 && temp % prime[t] == 0)
{
temp /= prime[t];
factors[t]++;
}
if (temp == 1) break;
}
}
}
c語言貪吃蛇最簡單代碼?
#include <stdio.h>
#include <windows.h>
#include <time.h>
#include <conio.h>
#define frame_height 20 //define map size
#define frame_width 40
#define UP 'w' //define operate key
#define DOWN 's'
#define LEFT 'a'
#define RIGHT 'd'
int i,j,k;
char ch=UP; //initial direction
int grow=0; //flag: if snake grow
struct Food{
int x;
int y;
}food;
struct Snake{
int x[50];
int y[50];
int len;
int speed;
}snake; //snake[0] is head
void init_map(void);
void update_food(void);
void move_snake(void);
int is_alive(void);
void get_speed(void);
void gotoxy(int x, int y);
int main()
{
init_map(); //初始化地圖
while(1)
{
update_food(); //是否產生食物
get_speed(); //獲取速度
move_snake(); //移動蛇身
Sleep(snake.speed); //移動速度
if(!(is_alive())) //蛇的死活(撞墻或自食)
break;
}
printf("Game Over!");
getch();
return 0;
}
//initialize
void init_map(void)
{
//initial food
srand(time(NULL));
food.x=rand()%(frame_height-2)+1;
food.y=rand()%(frame_width-2)+1;
gotoxy(food.x, food.y);
printf("!");
//initial snake
snake.x[0]=frame_height/2;
snake.y[0]=frame_width/2;
gotoxy(snake.x[0], snake.y[0]);
printf("@");
snake.len=3;
snake.speed=200;
for(k=1;k<snake.len;k++)
{
snake.x[k]=snake.x[k-1]+1;
snake.y[k]=snake.y[k-1];
gotoxy(snake.x[k], snake.y[k]);
printf("@");
}
//initial bar
for(j=0;j<frame_width;j++)
{
gotoxy(0, j);
printf("#");
gotoxy(frame_height-1, j);
printf("#");
}
for(i=1;i<frame_height-1;i++)
{
gotoxy(i, 0);
printf("#");
gotoxy(i, frame_width-1);
printf("#");
}
}
//generate food
void update_food()
{
if(snake.x[0]==food.x&&snake.y[0]==food.y)
{
srand(time(NULL));
food.x=rand()%(frame_height-2)+1;
food.y=rand()%(frame_width-2)+1;
gotoxy(food.x, food.y);
printf("!");
snake.len++;
grow=1;
}
}
//move snake
void move_snake()
{
if(kbhit())
ch=getch();
if(!grow)
{
gotoxy(snake.x[snake.len-1], snake.y[snake.len-1]);
printf(" ");
}
for(k=snake.len-1;k>0;k--)
{
snake.x[k]=snake.x[k-1];
snake.y[k]=snake.y[k-1];
}
switch(ch)
{
case UP: snake.x[0]--;break;
case DOWN: snake.x[0]++;break;
case LEFT: snake.y[0]--;break;
case RIGHT: snake.y[0]++;break;
default: break;
}
gotoxy(snake.x[0], snake.y[0]);
printf("@");
grow=0;
gotoxy(frame_height, 0);
}
//is alive
int is_alive(void)
{
if(snake.x[0]==0||snake.x[0]==frame_height-1||snake.y[0]==frame_width-1||snake.y[0]==0)
return 0;
for(k=1;k<snake.len;k++)
if(snake.x[k]==snake.x[0]&&snake.y[k]==snake.y[0])
return 0;
return 1;
}
//speed up
void get_speed(void)
{
if(snake.len<=6) snake.speed=200;
else if(snake.len<=10) snake.speed=100;
else if(snake.len<=20) snake.speed=50;
else if(snake.len<=30) snake.speed=30;
else snake.speed=20;
}
//move cursor
void gotoxy(int x, int y)
{
HANDLE hout;
COORD cor;
hout=GetStdHandle(STD_OUTPUT_HANDLE);
cor.X=y;
cor.Y=x;
SetConsoleCursorPosition(hout,cor);
}
c編程軟件哪個最好?
1、現在 C語言建議使用Microsoft Visual Studio 編程軟件比較好,應該該軟件與電腦Windows 7,8,10等系統兼容性比較好。
2、Microsoft Visual Studio(簡稱VS)是美國微軟公司的開發工具包系列產品。VS是一個基本完整的開發工具集,它包括了整個軟件生命周期中所需要的大部分工具,如UML工具、代碼管控工具、集成開發環境(IDE)等等。所寫的目標代碼適用于微軟支持的所有平臺,包括Microsoft Windows、Windows Mobile、Windows CE、.NET Framework、.NET Compact Framework和Microsoft Silverlight 及Windows Phone。
3、Visual Studio是目前最流行的Windows平臺應用程序的集成開發環境。最新版本為 Visual Studio 2015 版本,基于.NET Framework 4.5.2 。
以上就是關于c游戲編程代碼大全和按所給的公式計算組合數并輸出結果的相關問題解答,希望對你有所幫助。