C语言代码

#include
#include
#define WIDTH 20
#define LENGTH 31
//函数声明//
void draw(void);
void moveUp(void);
void moveDown(void);
void moveLeft(void);
void moveRight(void);
void change(void);

int map[WIDTH][LENGTH] =
{
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{2, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1},
{1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1},
{1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1},
{1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1},
{1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1},
{1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1},
{1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1},
{1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1},
{1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 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initgraph(620, 400);
setbkcolor(WHITE);
setfillcolor(BLUE);
bar(0,0,20,20);
setrendermode(RENDER_MANUAL);//防止刷图闪
draw();
char select;
while (!victory)
{
setrendermode(RENDER_AUTO);
select = getch();

switch(select)
{
case 72:
case 'W':
case 'w':
moveUp();
change();
setrendermode(RENDER_MANUAL);
cleardevice();//system("cls");
draw();
// setrendermode(RENDER_MANUAL);
break;
case 80:
case 'S':

case 's':
moveDown();
change();
setrendermode(RENDER_MANUAL);
cleardevice();//system("cls");
draw();
break;
case 75:
case 'A':
case 'a':
moveLeft();
change();
setrendermode(RENDER_MANUAL);
cleardevice();//system("cls");
draw();
break;
case 77:
case 'D':
case 'd':
moveRight();
change();
setrendermode(RENDER_MANUAL);
cleardevice();//system("cls");
draw();
break;
}
// setrendermode(RENDER_AUTO);
}
getch();
closegraph();
return 0;
}
void moveUp()//上移//
{
if (1 != map[x-1][y])
{
xx = x;
yy = y;
x = x - 1;

}
else
{
return ;
}
}

void moveDown()//下移//
{
if (1 != map[x+1][y])
{
xx = x;
yy = y;
x = x + 1;
}
else
{
return ;
}
}

void moveLeft()//左移//
{
if (1 != map[x][y-1])
{
xx = x;
yy = y;
y = y - 1;
}
else
{
return ;
}
}

void moveRight()//右移//
{
if (1 != map[x][y+1])
{
xx = x;
yy = y;
y = y + 1;
}
else
{
return ;
}
}

void change()
{
if (3 == map[x][y])
{
victory = true;
}
map[x][y] = 2;
map[xx][yy] = 0;
}
void draw()
{
PIMAGE img;
int val_1 = 0;
int val_2 = 0;

for (val_1=0; val_1--------------遍历数组//
{
for (val_2=0; val_2{
img = newimage();
getimage(img,0,0,20,20);
if (1 == map[val_1][val_2])//<>-----------------画墙//
{

putimage(val_2*20, val_1*20, img);
//注意顺序
}
}

}
delimage(img);
}




***********************************************
#include
#include
int main()
{
int N,a,b,c,d;
srand(time(0));
N=rand()%10000+1;
a=N/1000;
b=N/100%10;
c=N/10%10;
d=N/1%10;
printf("%d %d %d %d %d\n",N,a,b,c,d);
for(i=0;i<4;i++)
{
if(i=1)
{
num=a+b;
for(j=0;j<4;j++)
{

}
}

}
}
ws
键入学生学号和成绩,计算出总人数,并排列成绩学号输出。查找中,输入学号后查找出对应成绩!
#include
#define N 40
int main()
{
int score[N],n,big;
long num[N];
n=readscore(num,score);
printf("the totle stduents are:%d\n",n);
datesort(num,score,n);
printfscore(num,score,n);
printf("input stduent num and you can find him:");
big=findscore(num

,score,n);
printf("%d",score[big]);
}
int readscore(long num[],int score[])
{
int i=-1;
do
{
i++;
printf("input stduents ID and score:");
scanf("%ld%d",&num[i],&score[i]);
}
while(num[i]>=0&&score[i]>=0);
return i;
}
void datesort(long num[],int score[],int n)
{
int j,i,temp1,temp2;
for(i=0;i{
for(j=i+1;j{
if(score[j]>score[i])
{
temp1=score[j];
score[j]=score[i];
score[i]=temp1;
temp2=num[j];
num[j]=num[i];
num[i]=temp2;
}
}
}
}
void printfscore(long num[],int score[],int n)
{
int i;
for(i=0;i{
printf("%4ld%4d\n",num[i],score[i]);
}
}
int findscore(long num[],int score[],int n)
{
int stduentnum,i;
scanf("%ld",&stduentnum);
for(i=0;i{
if(stduentnum==num[i])
{
return i;
}
}

}

oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
#include
#include
int main()
{
int *p=NULL,n;
double aver;
printf("input how mang stduents:");
scanf("%d",&n);
p=(int*)malloc(n*sizeof(int));
inputarray(p,n);
aver = average(p,n);
printf("aver=%.lf\n",aver);
freep(p);
return 0;
}
void inputarray(int *p,int n)
{
int i;
for(i=0;i{
printf("input students score:%d",n);
scanf("%d",&p[i]);
}

}
double average(int *p,int n)
{
int sum=0,i;
for(i=0;i{
sum=sum+p[i];
}
return (double)sum/n;
}

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#include
#include
typedef struct date
{
int year;
int month;
int day;
}DATE;
typedef struct student
{
long studentID;
char studentname[10];
char studentsex;
DATE birthday;
int score[4];
}STUDENT;
int main()
{
int i,j,sum[30];
STDUENT stu[30]={{100310121,"王刚",'M',{1991.5.19},{72,83,90,82}},
{{100310122,"小明",'M',{1992.8.20},{88,82,95,88}}};
for(i=0;i<4;i++)
{
sum[i]=0;
for(j=0;j<4;j++)
{
sum[i]=sum[i]+stu[i].score[j];
}
}

}

****************************************************************************************
#include
#define N 30
typedef struct date
{
int year;
int month;
int day;
}DATE;
typedef struct student
{
long studentID;
char studentname[10];
char studentsex;
DATE birthday;
int score[4];
}STUDENT;
void inputscore(STUDENT stu[],int n,int m);
void averscore(STUDENT stu[],float aver[],int n,int m);
void printscore(STUDENT stu[],float aver[],int n,int

m);
int main()
{

float aver[N];
STUDENT stu[N];
int n;
printf("how many student?:");
scanf("%d",&n);
inputscore(stu,n,4);
averscore(stu,aver,n,4);
printscore(stu,aver,n,4);
return 0;
}
void inputscore(STUDENT stu[],int n,int m)
{
int i,j;
for(i=0;i{
printf("input record%d:\n",i+1);
scanf("%ld",&stu[i].studentID);
scanf("%s", stu[i].studentname);
scanf("%c",&stu[i].studentsex);
scanf("%d",&stu[i].birthday.year);
scanf("%d",&stu[i].birthday.month);
scanf("%d",&stu[i].birthday.day);
for(j=0;j{
scanf("%d",&stu[i].score[j]);
}
}
}
void averscore(STUDENT stu[],float aver[],int n,int m)
{
int i,j,sum[N];
for(i=0;i{
sum[i]=0;
for(j=0;j{
sum[i]=sum[i]+stu[i].score[j];

}
aver[i]=(float)sum[i]/m;
}
}
void printscore(STUDENT stu[],float aver[],int n,int m)
{
int i,j;
printf("results:\n");
for(i=0;i{
printf("%10ld%8s%3c%6d/%02d/%02d",stu[i].studentID,
stu[i].studentname,stu[i].studentsex,stu[i].birthday.year,
stu[i].birthday.month,stu[i].birthday.day);
for(j=0;j{
printf("%4d",stu[i].score[j]);
}
printf("%6.lf\n",aver[i]);
}
}


@@@@
1到8排序代码
#include
#include
#include
int main()
{
int Cells[8];
int i;
int a=0;
int b=0;
for (i=0; i<9; i++)
{
b++;
srand(i);
Cells[i]=rand()%8+1;
if(i>1)
{
for(a=0; a{
if (Cells[i]==Cells[a])
{

Cells[i]=(Cells[i]+1)%8+1;
}
}
}
}
printf("游戏开始:\n%d %d %d\n%d %d\n%d %d %d\n\n",Cells[0],Cells[1],Cells[2],Cells[7],Cells[3],Cells[6],Cells[5],Cells[4]);


int temp=0;
int ct=0;
int nu=1;
int x=0;
for (ct=0; ct<6; ct++)
{
for (x=0; x<6; x++)
{
if(Cells[x]>Cells[x+1])
{
nu++;
temp=Cells[x];
Cells[x]=Cells[x+1];
Cells[x+1]=temp;
temp=0;
printf("第%d步:\n%d %d %d\n%d %d\n%d %d %d\n\n",nu,Cells[0],Cells[1],Cells[2],Cells[7],Cells[3],Cells[6],Cells[5],Cells[4]);
}

}
}
printf("游戏结束:\n%d %d %d\n%d %d\n%d %d %d\n\n",Cells[0],Cells[1],Cells[2],Cells[7],Cells[3],Cells[6],Cells[5],Cells[4]);
return 0;
}
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#include
int main()
{
int a,b,i;

printf("《数字翻译器》\n");
printf("请输入数字:");
scanf("%d",&a);
for(i=0;i++)
{
if(a=0)
break;




}

char vvdate[19][10]={"zero","one","two","there","four","five","six","seven","eight","nine","ten",
"eleven","twelve","thirteen","fourteen","fifteen","sixteen ","seventeen ","eighteen ","nineteen"};
char famile[8][8]={"twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"};
printf("%c",date[4][10]);

}

相关文档
最新文档